joehl@web.de
2000-Dec-28 19:04 UTC
[Rd] some (may be related) problems with windows(rescale=) (PR#794)
############################################################################### 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. ############################################################################### ## 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> fixedx y din 9.2291667 6.3854167 fin 9.2291667 6.3854167 pin 8.0666667 4.6604167 text 0.1394628 0.2896737> fitx y din 9.22916667 6.3854167 fin 9.22916667 6.3854167 pin 8.79000000 5.7337500 text 0.07935154 0.1122302> Rx 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 ## 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> fixedx y din 9.1666667 6.1562500 fin 9.1666667 6.1562500 pin 8.0041667 4.4312500 text 0.1405518 0.3046544> fitx y din 9.1666667 6.1562500 fin 9.1666667 6.1562500 pin 8.0041667 4.4312500 text 0.1405518 0.3046544> Rx 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> 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. ############################################################################### --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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
joehl@web.de
2000-Dec-29 17:11 UTC
[Rd] some (may be related) problems with windows(rescale=) (PR#794)
Dear Prof. Brian Ripley, Thank you for your answer. You convinced me on one important point, but some issues remain open (revised bug status at the end of this message)> If these things bother you, could you please supply fixes?Given that I don't have much experience in C coding, given that I don't know any internals of the R graphics engine (where I think a solution would be best), given that I don't have ever compiled R for Windows (where obviously the rescale stuff happens), it is currently too expensive for me to attack that. What I definitely can offer is testing and giving replicable bug reports. Also, given that I am not a member of r-devel and that some r-devel don't think these are clearly bugs, I shrink from producing code that might never make it into R.> [snipped] > 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. > [snipped]Running the risk to repeat me: I am convinced that R like S+ needs a stable representation layer to which a programmer can refer. This is the layer where we talk about "let's layout a DIN A3 Paper, let's use 2 inches margins" and so on and this layer should be independent of actual window size (presentation layer). One might whish, that R's grapic parameter do not refer to absolute measures and divide the device area rather with relative measures: "let's have 10% margins". However, R allows to specify some parameter in absolute measures (e.g. par(mai=)) and more important some parameters are not free of absolute measures as par(cex=1) refers to a fixed ont size, not to a fixed fraction of the device size. Because of this the RO-device feature par("fin") to me appears not to be an arbitrary size and should be kept stable.> Possibly. I don't think the device size is very interesting after > rescaling. What are you using it for?Well, of course I try to avoid using it. Checking this more thoroughly I see that with windows(rescale="fit") I INDEED CAN IGNORE par("din") as long as I avoid making any specifications in inches. Requesting a 16 inch device and getting initially 9 inches CEX is rescaled appropriately, WITH RESPECT to the intended 16 inch device. Note that we now introduced a device which looks like 9 inch on screen with too small fonts, if asked it tells the user 'I am a 9 inch device (par("din"))' and it does not tell the user 'well, in fact my original size is 16 inches, don't forget'. But this is OK, the rescaling basically works. Thus I have to revise the interpretation of the phenomenon which I observed in comparing the character sizes of the three rescale modes: What I called "strange character sizes" in windows(rescale="fit") seems to make sense. It's rather windows(rescale="fixed") which gives problematic character sizes. Example Finding out the necessary par(cex=) which allows a certain amount of text to fit in a certain fraction of the device size. =======================windows(rescale="fixed") does not do rescaling after device initializiation, it's basic idea is to not change the device size at all. However, the automatic initial rescaling destroys this idea: if you require a 16 inch device and you get 9 inches, then you can only find out which cex is optimal for 9 inches but applying the result to a 16 inch device fails. In short: character size is not correct with respect to those 16 inches we requested, but is correct with respect to those 9 inches we get instead. Thus the current implementation does not make sense with devices bigger than the screen. ======================= # I intend to layout DIN A3 width <- 16.53543 height <- 11.69291 jandltext <- "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)" windows(width=width, height=height, rescale="fixed") # using windows() I find out that with cex=3.2 the following commands give a text that exacly fills the plot area (horizontally) par(cex=1) par(mai=c(0,0,0,0)) plot.new() par(usr=c(0,2,0,2)) par(c("din","fin","pin")) par("usr") text(1,1, jandltext, cex=3.2) dev.off() postscript(file = "c:/temp/t.ps", paper="special", width=width, height=height) # now applying THE SAME commands gives NOT a text that exacly fills the plot area (horizontally). par(cex=1) par(mai=c(0,0,0,0)) plot.new() par(usr=c(0,2,0,2)) par(c("din","fin","pin")) par("usr") text(1,1, jandltext, cex=3.2) dev.off() =====================by constrast windows(rescale="fit") works ===================== # I intend to layout DIN A3 width <- 16.53543 height <- 11.69291 jandltext <- "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)" windows(width=width, height=height, rescale="fit") # using windows() I find out that with cex=5.8 the following commands give a text that exacly fills the plot area (horizontally) par(cex=1) par(mai=c(0,0,0,0)) plot.new() par(usr=c(0,2,0,2)) par(c("din","fin","pin")) par("usr") text(1,1,jandltext, cex=5.8) dev.off() postscript(file = "c:/temp/t.ps", paper="special", width=width, height=height) # now applying THE SAME commands WORKS par(cex=1) par(mai=c(0,0,0,0)) plot.new() par(usr=c(0,2,0,2)) par(c("din","fin","pin")) par("usr") text(1,1,jandltext, cex=5.8) dev.off() However repeated resizing of the window does increase the shown font sizes, look at that: width <- 8 height <- 6 jandltext <- "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.8 info <- function(){ user <- strwidth(jandltext, cex=cex, units="user") inches <- strwidth(jandltext, cex=cex, units="inches") pin <- par("pin") din <- par("din") data.frame(din=din[1], aspectratio=din[1]/din[2], pintodin=pin[1]/din[1], struser=user, strinchtopin=inches/pin[1], strinch=inches) } windows(width=width, height=height, rescale="fit") # this one serves as reference for initial window size windows(width=width, height=height, rescale="fit") par(cex=1) par(mai=c(0,0,0,0)) plot.new() par(usr=c(0,1,0,1)) par(c("din","fin","pin")) par("usr") text(0.5,0.5,jandltext, cex=cex) # Initial measures print(static <- info()) # now some VERTICAL resizing and bring window back to original size print(static <- rbind(static, info())) # we never touched horizontal window size but horiz din differs, strwidthInInches differs not # now some VERTICAL resizing and bring window back to original size print(static <- rbind(static, info())) # now everything differs> print(static <- rbind(static, info()))din aspectratio pintodin struser strinchtopin strinch 1 8.166667 1.326565 1 0.9859694 0.9859694 8.052083 # start 2 6.291905 1.023768 1 1.2797528 1.2797528 8.052083 # after some vertical resizing 3 8.166667 1.390765 1 1.2908163 1.2908163 10.541667 # after some horizontal resizing So here is my revised bug status: 1a) windows(rescale="fixed") does not keep original device size 1b) windows(rescale="fixed") gives problematic character sizes (because of 1a) 2) wrong row distances with windows(rescale="fit") This phenomenon also observed under different circumstances see todays mail to r-help 3a) windows(rescale="fit") destroys aspect ratio 3b) repeated rescaling destroys proper font size as well Kind regards and best wishes for 2001 Jens Oehlschlägel _______________________________________________________________________________ Alles unter einem Dach: Informationen, Fun, E-Mails. Bei WEB.DE: http://web.de Die große Welt der Kommunikation: E-Mail, Fax, SMS, WAP: 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Maybe Matching Threads
- some (may be related) problems with windows(rescale=) (PR#795)
- Re: some problems with windows(rescale=) (PR#794)
- Is this a bug? Having cex!=1 before setting par(mai=) gives strange line spacings.
- rsync 2.6.0 and Solaris 8
- Can someone please have a look at this query on stackoverflow?