[Rd] some (may be related) problems with windows(rescale=) (PR#795)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Thu, 28 Dec 2000 21:23:18 +0100 (MET)


If these things bother you, could you please supply fixes?  For some reason
you omitted the part of the help page dealing with one of these (which is
as documented), and I also think you are confusing `plot' and `device'
sizes. The latter will be the displayed device surface, I believe.

Nothing on the help page suggested that the fine details of the R read-only
parameters will be as you expected after re-scaling the plot, and it never
occurred to me that anyone would expect so.  As they are reported by the R
graphics engine (which is used unchanged), I expect they are correct in one
of the multiple interpretations.

On Thu, 28 Dec 2000 joehl@web.de wrote:

> ###############################################################################
> 
> Before reporting 4 problems with windows(rescale=) I want to congrat on R1.2 and to thank r-developers for quickly adding the rescale workaround to the windows version.
> 
> Happy New Year
> 
> 
> Jens Oehlschlaegel
> 
> 
> ###############################################################################
> 
> 
> 
> ###############################################################################
> ## windows(rescale="fixed") does not keep original device size 
> ## (probably device initialization error)
> ###############################################################################
> 
> dev.show <- function(){
> 	din <- par("din")
> 	c(width=din[1], height=din[2], aspectratio=din[1]/din[2])
> }
> width <- 42/2.54
> height <- 29.7/2.54
> 
> > width
> [1] 16.53543
> > height
> [1] 11.69291
> > width/height
> [1] 1.414141
> 
> 
> > windows(width=width, height=height, rescale="R")
> > dev.show()
>       width      height aspectratio 
>    9.229167    6.385417    1.445351 
> > dev.off()
> null device 
>           1 
> > windows(width=width, height=height, rescale="fixed")
> > dev.show()
>       width      height aspectratio 
>    9.229167    6.385417    1.445351 
> > dev.off()
> null device 
>           1 
> > windows(width=width, height=height, rescale="fit")
> > dev.show()
>       width      height aspectratio 
>    9.229167    6.385417    1.445351 
> 
> 
> ## Shouldn't at least rescale="fixed" give the desired device size and aspect ratio?
> ## The Help to windows() says:
> ## Using `"fixed"' will leave
> ##     the plot size unchanged, adding scrollbars if part of the plot is
> ##     obscured. This setting also affects the initial re-scaling if the
> ##     specified window size is too big.   

I don't think so.  It says the `plot' size, not the `device' size which is
what par("din") reports.

> ###############################################################################
> ## windows(rescale="fit") gives strange character sizes 
> ## (looks like device initialization error)
> ###############################################################################
> 
> 
> ## In the following examples the created devices seem to be equally initialized with respect to par(din)
> ## However, with windows(rescale="fit") I observe different par(pin) and 
different character sizes in text() and strwidth()
> 
> width <- 16.53543
> height <- 11.69291
> 
> windows(width=width, height=height, rescale="fixed")
> par("cex")
> plot(0:2,0:2, type="n")
> text(1,1,"abc\ndef", cex=2)
> text(1,0.5,"fixed", cex=2)
> temp <- t(sapply(par(c("din", "fin", "pin")),c))
> colnames(temp) <- c("x", "y")
> temp <- rbind(temp, text=c(strwidth("abc\ndef", cex=2), strheight("abc\ndef", cex=2)))
> fixed <- temp
> 
> windows(width=width, height=height, rescale="fit")
> par("cex")
> plot(0:2,0:2, type="n")
> text(1,1,"abc\ndef", cex=2)
> text(1,0.5,"fit", cex=2)
> temp <- t(sapply(par(c("din", "fin", "pin")),c))
> colnames(temp) <- c("x", "y")
> temp <- rbind(temp, text=c(strwidth("abc\ndef", cex=2), strheight("abc\ndef", cex=2)))
> fit <- temp
> 
> windows(width=width, height=height, rescale="R")
> par("cex")
> plot(0:2,0:2, type="n")
> text(1,1,"abc\ndef", cex=2)
> text(1,0.5,"R", cex=2)
> temp <- t(sapply(par(c("din", "fin", "pin")),c))
> colnames(temp) <- c("x", "y")
> temp <- rbind(temp, text=c(strwidth("abc\ndef", cex=2), strheight("abc\ndef", cex=2)))
> R <- temp
> 
> # now compare
> fixed
> fit
> R
> 
> > fixed
>              x         y
> din  9.2291667 6.3854167
> fin  9.2291667 6.3854167
> pin  8.0666667 4.6604167
> text 0.1394628 0.2896737
> > fit
>               x         y
> din  9.22916667 6.3854167
> fin  9.22916667 6.3854167
> pin  8.79000000 5.7337500
> text 0.07935154 0.1122302
> > R
>              x         y
> din  9.2291667 6.3854167
> fin  9.2291667 6.3854167
> pin  8.0666667 4.6604167
> text 0.1394628 0.2896737
> 
> 
> > ## It looks like character size of windows(rescale="fit") refers to originally intended device size of 
> > ## width=16.53543, height=11.69291 as 
> > fit["text", "x"]/R["din", "x"]*width
> [1] 0.1415101
> > ## aprox. equal 
> > fixed["text", "x"]
> [1] 0.1405518

As documented:

  Using \code{\link{strwidth}} or
  \code{\link{strheight}} after a window has been rescaled gives
  dimensions in the original units, but only approximately as they are
  derived from the metrics of the rescaled fonts.

> ## If we now repeat this procedure with device sizes small enough to avoid initial rescaling
> ## the phenomenon disappears

Right, as documented.

> ###############################################################################
> ## wrong row distances with windows(rescale="fit")
> ## (looks like device initialization error)
> ###############################################################################
> 
> 
> width <- 16.53543
> height <- 11.69291
> 
> ## as a reference
> windows(width=width, height=height, rescale="fixed")
> plot(0:2,0:2, type="n")
> text(1,1,"there is hardly anything i know for sure\nneither of the future nor of the past\nnor should i know what to ask\nif the person answering was you\n\n(Ernst Jandl, stanzen)"
> ,cex=2)
> 
> ## Here rows are too close together
> windows(width=width, height=height, rescale="fit")
> plot(0:2,0:2, type="n")
> text(1,1,"there is hardly anything i know for sure\nneither of the future nor of the past\nnor should i know what to ask\nif the person answering was you\n\n(Ernst Jandl, stanzen)"
> ,cex=3)

I can't reproduce that.  It may depend on the fonts available.

> ## Specifying smaller device size thus avoiding initial rescaling 
> ## makes the problem disappear
> 
> width <- 9
> height <- 6
> 
> windows(width=width, height=height, rescale="fit")
> plot(0:2,0:2, type="n")
> text(1,1,"there is hardly anything i know for sure\nneither of the future nor of the past\nnor should i know what to ask\nif the person answering was you\n\n(Ernst Jandl, stanzen)"
> ,cex=3)
> 
> ## Once correctly initialized further rescaling using the mouse does retain correct distances
> 
> dev.off()
> dev.off()
> dev.off()
> 
> 
> 
> ###############################################################################
> ## windows(rescale="fit") destroys aspect ratio 
> ## (looks like device initialization error)
> ###############################################################################
> 
> 
> dev.show <- function(){
> 	din <- par("din")
> 	c(width=din[1], height=din[2], aspectratio=din[1]/din[2])
> }
> width <- 42/2.54
> height <- 29.7/2.54
> 
> > width
> [1] 16.53543
> > height
> [1] 11.69291
> > width/height
> [1] 1.414141
> 
> 
> ## create a device
> > windows(width=width, height=height, rescale="fit")
> > dev.show()
>       width      height aspectratio 
>    9.229167    6.385417    1.445351 
> 
> ## some resizing of the window BEFORE plot() is called
> # par("din") doesn't SEEM to change
> > dev.show()
>       width      height aspectratio 
>    9.229167    6.385417    1.445351 
>    
> # but in fact calling plot() and dev.show()
> > plot(0,0)
> > dev.show()
>       width      height aspectratio 
>    6.321506    5.562500    1.136451 
> 
> ## now some resizing of the window AFTER plot() is called
> > dev.show()
>       width      height aspectratio 
>    4.708333    4.500471    1.046187 
> > dev.show()
>       width      height aspectratio 
>    4.718750    3.297956    1.430811 
> > dev.show()
>       width      height aspectratio 
>   3.3255361   4.4375000   0.7494166 
> > dev.show()
>       width      height aspectratio 
>   1.4091170   5.1145833   0.2755096 
> > dev.show()
>       width      height aspectratio 
>   1.4062500   5.1145833   0.2749491 
> > dev.show()
>       width      height aspectratio 
>   0.4701945   3.3854167   0.1388882 
>   
> ## we got very differing aspect ratios
> ## One reason for that COULD be that the initially intended device sizes are not kept, 
> ## so that many rescalings cumulate the deviations.
> ## May be par(din) should not be changed at all (keep the representation layer stable)
> ## and only apply rescaling/zooming/scrolling only to the graphical presentation.

Possibly.  I don't think the device size is very interesting after
rescaling.  What are you using it for?

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._