[R] Problem with viewports, print.trellis and more/newpage

Sebastien Bihorel sebastien.bihorel at cognigencorp.com
Thu May 14 22:58:52 CEST 2009


Dear R-users,

I have got the following problem. I need to create 4x2 arrays of 
xyplot's on several pages. The plots are created within a loop and 
plotted using the print function. It seems that I cannot find the proper 
grid syntax with my viewports, and the more/newpage arguments.

The following script is a simplification but hopefully will suffice to 
illustrate my problem. Any suggestion from the list would be greatly 
appreciated.

Sebastien

#########

library(lattice)

foo <- data.frame(x=1:10,y=1:10)

for (i in 1:4) {
  #isnewpage <-     FALSE

  plots <- xyplot(y~x,data=foo)
 
  pushViewport(viewport(x=0,
                        y=0,
                        width=1,
                        height=0.95,
                        just=c(0,0)))

  print(plots, split=c(1,1,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(2,1,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(1,2,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(2,2,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(1,3,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(2,3,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(1,4,2,4), more=T)#, newpage=isnewpage)
  print(plots, split=c(2,4,2,4), more=F)#, newpage=isnewpage)
     
  popViewport()
     
  pushViewport(viewport(x=0,
                        y=0.95,
                        width=1,
                        height=0.05,
                        just=c(0,0)))
      grid.text(label = i,
                just = c("centre","centre"),
                gp = gpar(fontsize = 10, font = 2))
      popViewport()
     
  # Updates isnewpage
  # isnewpage <- TRUE
}
-- 
*Sebastien Bihorel, PharmD, PhD*
PKPD Scientist
Cognigen Corp
Email: sebastien.bihorel at cognigencorp.com 
<mailto:sebastien.bihorel at cognigencorp.com>
Phone: (716) 633-3463 ext. 323




More information about the R-help mailing list