Skip to content

Using strwidth before plotting

3 messages · Duncan Murdoch, Brian Ripley

#
In the plotcorr() function in the ellipse package, I want to position
things differently depending on the size of the labels.  I can use
strwidth to find out the length of the labels, but only when there's a
plot window open:  it won't open one.

Question:  What function call says:  make sure there's a window open
(i.e. do what plot() does before it starts plotting)?

I don't think I can use plot.new() or frame(), because I don' t want
to leave a blank page in the plot history if there was already a
window open.

Duncan Murdoch


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Tue, 16 Apr 2002, Duncan Murdoch wrote:

            
Call par(), e.g. par("font")
(That is indeed what happens.)

You can find if there is a device open by looking at length(.Devices) > 1
or dev.cur() > 1.
#
On Wed, 17 Apr 2002, Prof Brian D Ripley wrote:

            
However, you could use plot.new(); par(new=TRUE)
What the internal code does can be reproduced in R by

if(length(.Devices) == 1 || dev.cur() == 1) {
    dev <- getOption("device")
    if(is.character(dev) && length(dev) > 0) get(dev)()
}

dev.cur includes a check that .Devices exists, but it is created in
InitGraphics before interactive R code is accepted, so the check must
always succeed and the above code is safe.