[R] Fixing the physical size of Trellis graphs panels

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Apr 10 23:51:38 CEST 2008


On 4/10/08, Sébastien <pomchip at free.fr> wrote:
> Dear R-users,
>
>  Please consider the following script:
>
>  #####
>
>  library(lattice)
>  ID <- rep(1:8,each=2)
>  x <- rep (c(1,2),8)
>  y <- c(rep(c(0.5,2),4),rep(c(50,1000),4))
>  df<-data.frame(ID,x,y)
>  g <- rep(1:2,each=8)
>  df.split<-split(df,g)
>
>  df.split
>
>  pdf(file="C:/Test.pdf")
>
>  for (i in 1:2) {
>  mydf<-as.data.frame(df.split[i])
>  myplot<-xyplot(mydf[,3]~mydf[,2]|mydf[,1],
>        data=mydf,
>        layout=c(2,2))
>  print(myplot)
>  }
>  dev.off()
>
>  You will find that the physical size of the panels are different on page
>  1 and 2 because the axis labels have different length. Is it possible to
>  fix the dimension of the panels regardless of the length of the axis labels?

Yes, look at the entry for panel.width and panel.height in
?print.trellis. You could use it as

print(myplot, panel.width = list(x = 3, unit = "inches"))

etc. See ?unit in the grid package for details.

-Deepayan


More information about the R-help mailing list