Skip to content

some (may be related) problems with windows(rescale=) (PR#794)

1 message · Jens Oehlschlägel

#
###############################################################################

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
[1] 16.53543
[1] 11.69291
[1] 1.414141
width      height aspectratio 
   9.229167    6.385417    1.445351
null device 
          1
width      height aspectratio 
   9.229167    6.385417    1.445351
null device 
          1
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.   



###############################################################################
## 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
x         y
din  9.2291667 6.3854167
fin  9.2291667 6.3854167
pin  8.0666667 4.6604167
text 0.1394628 0.2896737
x         y
din  9.22916667 6.3854167
fin  9.22916667 6.3854167
pin  8.79000000 5.7337500
text 0.07935154 0.1122302
x         y
din  9.2291667 6.3854167
fin  9.2291667 6.3854167
pin  8.0666667 4.6604167
text 0.1394628 0.2896737
[1] 0.1415101
[1] 0.1405518


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

dev.off()
dev.off()
dev.off()

width <- 9.2291667
height <- 6.3854167

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
x         y
din  9.1666667 6.1562500
fin  9.1666667 6.1562500
pin  8.0041667 4.4312500
text 0.1405518 0.3046544
x         y
din  9.1666667 6.1562500
fin  9.1666667 6.1562500
pin  8.0041667 4.4312500
text 0.1405518 0.3046544
x         y
din  9.1666667 6.1562500
fin  9.1666667 6.1562500
pin  8.0041667 4.4312500
text 0.1405518 0.3046544



###############################################################################
## 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)


## 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
[1] 16.53543
[1] 11.69291
[1] 1.414141


## create a device
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
width      height aspectratio 
   9.229167    6.385417    1.445351 
   
# but in fact calling plot() and dev.show()
width      height aspectratio 
   6.321506    5.562500    1.136451 

## now some resizing of the window AFTER plot() is called
width      height aspectratio 
   4.708333    4.500471    1.046187
width      height aspectratio 
   4.718750    3.297956    1.430811
width      height aspectratio 
  3.3255361   4.4375000   0.7494166
width      height aspectratio 
  1.4091170   5.1145833   0.2755096
width      height aspectratio 
  1.4062500   5.1145833   0.2749491
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.



###############################################################################


--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = x86
 os = Win32
 system = x86, Win32
 status = 
 major = 1
 minor = 2.0
 year = 2000
 month = 12
 day = 15
 language = R

Windows NT 4.0 (build 1381) Service Pack 6

Search Path:
 .GlobalEnv, package:ctest, Autoloads, package:base

______________________________________________________________________________
Die Fachpresse ist sich einig: WEB.DE 15mal Testsieger! Kostenlos E-Mail, 
Fax, SMS, Verschlüsselung, POP3, WAP....testen Sie uns! http://freemail.web.de


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