[R] panel.text and saving to pdf

Dieter Menne dieter.menne at menne-biomed.de
Fri Jun 26 10:53:27 CEST 2009


Willem Vervoort <w.vervoort <at> usyd.edu.au> writes:

> I am not sure what I am doing wrong, but I have some unexplained behaviour
when saving a lattice graph
> including text to a pdf file. The text seems to move around. It must have
something to do with the way
> coordinates are set in devices other than jpg.
> 
> today <- format(Sys.Date(),"%Y%m%d")
> 
> x <- runif(500)
> y <- rnorm(500)
> 
> foo <- data.frame(x = x, y = y, z = rep(c("a","b"),250))
> require(lattice)
> 
> xyplot(x~y|z,data=foo)
> panel.text(370,470,"silly graph",cex=1.2,font=2)

Take this plot, resize its window: you will note that the "silly graph" moves
relative to the graphics. The same is true for the higher-resolution pdf output. 
To get around this, and to have the text positioned in a relative scaled
position, you could create a special panel function and call panel.text there.
See the examples at the bottom of the xyplot documentation page.

Dieter




More information about the R-help mailing list