[R] lattice/ grid.layout/ multiple graphs per page

McClatchie, Sam (PIRSA-SARDI) mcclatchie.sam at saugov.sa.gov.au
Fri Jul 29 04:13:15 CEST 2005


Background:
OS: Linux Mandrake 10.1
release: R 2.0.0
editor: GNU Emacs 21.3.2
front-end: ESS 5.2.3
---------------------------------

>-----Original Message-----
>From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com]
>Sent: Friday, 29 July 2005 3:44 AM
>To: McClatchie, Sam (PIRSA-SARDI)
>Cc: R-Help-Request (E-mail)
>Subject: Re: [R] lattice/ grid.layout/ multiple graphs per page

>Depends on the details of your 'working trellis code'. Are you using
>print() explicitly with 'newpage=FALSE'? See ?print.trellis for
>details.
>
>Deepayan

-------------------------
Sorry Deepayan, I should have included the full code originally.
Here it is, with your suggestion for using the newpage=FALSE option to
print(). I still have not got it right. 

"egg.and.larvae.vs.intermittency.conditioned.plots" <-
  function()
{
  library(lattice)
  library(grid)

  n <- layout(matrix(c(1,2,3,4), 2,2))
                                        #grid.newpage()
                                        #pushViewport(viewport(layout =
grid.layout(2, 2)))
 
#pushViewport(viewport(layout.pos.col=1, layout.pos.row=1))
            
                                        #trellis.device(postscript,
#file="../figures/egg.and.larvae.vs.intermittency.conditioned.plots.2001.egg
s.ps",horizontal=FALSE,# color=TRUE)

  trellis.par.set(par.xlab.text = list(cex = 1.5))
  trellis.par.set(par.ylab.text = list(cex = 1.5))
  trellis.par.set(axis.text = list(cex = 1.2))
  
  d.2001 <-
mn.ts.e.zoo.vol.vol.filt.anchovy.egg.larv.mn.fluor.wire.intermittency.2001
  d.2002 <-
mn.ts.e.zoo.vol.vol.filt.anchovy.egg.larv.mn.fluor.wire.intermittency.2002
                                        #browser()
  
  attach(d.2001)
                                        #intermittency.blocks <-
cut(percent.unstable, breaks=c(0,10,20,30,40,50))
  intermittency.blocks <- cut(percent.unstable,
breaks=c(0,5,10,15,20,25,30,35,40,45,50))

###trellis plots, 2001 data
  int <- matrix(c(0,50,45,100,90,200), ncol=2, byrow=TRUE)  
  egg.counts <- shingle(d.2001$eggs2.Pilch.Eggs, intervals = int)
  out1 <- bwplot(eggs2.Pilch.Eggs ~  intermittency.blocks |  egg.counts,
                 data = d.2001,
                 xlab = "intermittency  (% of water column unstable)",
                 ylab = "eggs m^2",
                 main = "2001",
                 ylim = c(0,200),
                 layout = c(1,3),
                 auto.key = T)
  print(out1, newpage=F)
  par(par.old) 
                                        #  graphics.off()
  
                                        #  x11()
                                        # trellis.device(postscript,
#file="../figures/egg.and.larvae.vs.intermittency.conditioned.plots.2001.lar
vae.ps",horizontal=FALS#E, color=TRUE)

 
#pushViewport(viewport(layout.pos.col=1, layout.pos.row=2))
  trellis.par.set(par.xlab.text = list(cex = 1.5))
  trellis.par.set(par.ylab.text = list(cex = 1.5))
  trellis.par.set(axis.text = list(cex = 1.2))
  
  int <- matrix(c(0,50,45,100,90,200), ncol=2, byrow=TRUE)  
  larval.counts <- shingle(d.2001$eggs2.Pilch.Larv, intervals = int)
  out2 <- bwplot(eggs2.Pilch.Larv ~  intermittency.blocks |  larval.counts,
                 data = d.2001,
                 xlab = "intermittency (% of water column unstable)",
                 ylab = expression(paste("larvae ",m^{-2})),
                 main = "2001",
                 ylim = c(0,200),
                 layout = c(1,3),
                 auto.key = T)
  detach("d.2001")
  print(out2, newpage=F)
                                        #graphics.off()
  
###trellis plots, 2002 data
  attach(d.2002)
                                        #  x11()
                                        #trellis.device(postscript,
#file="../figures/egg.and.larvae.vs.intermittency.conditioned.plots.2002.egg
s.ps",horizontal=FALSE#, color=TRUE)

 
#pushViewport(viewport(layout.pos.col=2, layout.pos.row=1))
  trellis.par.set(par.xlab.text = list(cex = 1.5))
  trellis.par.set(par.ylab.text = list(cex = 1.5))
  trellis.par.set(axis.text = list(cex = 1.2))
  
  int <- matrix(c(0,50,45,100,90,200), ncol=2, byrow=TRUE)  
  egg.counts <- shingle(d.2002$eggs2.Pilch.Eggs, intervals = int)
  out3 <- bwplot(eggs2.Pilch.Eggs ~  intermittency.blocks |  egg.counts,
                 data = d.2002,
                 xlab = "intermittency  (% of water column unstable)",
                 ylab = "eggs m^2",
                 main = "2002",
                 ylim = c(0,200),
                 layout = c(1,3),
                 auto.key = T)
  
  par(par.old)
                                        #graphics.off()
  print(out3, newpage=F)
                                        # x11()
                                        # trellis.device(postscript,
#file="../figures/egg.and.larvae.vs.intermittency.conditioned.plots.2002.lar
vae.ps",horizontal=FALS#E, color=TRUE)

 
#pushViewport(viewport(layout.pos.col=2, layout.pos.row=2))
  trellis.par.set(par.xlab.text = list(cex = 1.5))
  trellis.par.set(par.ylab.text = list(cex = 1.5))
  trellis.par.set(axis.text = list(cex = 1.2))
  
  int <- matrix(c(0,50,45,100,90,200), ncol=2, byrow=TRUE)   
  larval.counts <- shingle(d.2002$eggs2.Pilch.Larv, intervals = int)
  out4 <- bwplot(eggs2.Pilch.Larv ~  intermittency.blocks |  larval.counts,
                 data = d.2002,
                 xlab = "intermittency (% of water column unstable)",
                 ylab = expression(paste("larvae ", m^{-2})),
                 main = "2002",
                 ylim = c(0,200),
                 layout = c(1,3),
                 auto.key = T)
  print(out4, newpage=F)
  par(par.old)
                                        #  graphics.off()
  detach("d.2002")
}

>-----Original Message-----
>From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com]
>Sent: Friday, 29 July 2005 3:44 AM
>To: McClatchie, Sam (PIRSA-SARDI)
>Cc: R-Help-Request (E-mail)
>Subject: Re: [R] lattice/ grid.layout/ multiple graphs per page
>
>
>On 7/27/05, McClatchie, Sam (PIRSA-SARDI)
><mcclatchie.sam at saugov.sa.gov.au> wrote:
>> Background:
>> OS: Linux Mandrake 10.1
>> release: R 2.0.0
>> editor: GNU Emacs 21.3.2
>> front-end: ESS 5.2.3
>> ---------------------------------
>> Colleagues
>> 
>> I have a set of lattice plots, and want to plot 4 of them on 
>the page.
>> I am having trouble with the layout.
>> 
>> grid.newpage()
>> pushViewport(viewport(layout = grid.layout(2,2)))
>> pushviewport(viewport(layout.pos.col = 1, layout.pos.row = 1))
>> working trellis graph code here
>> pushviewport(viewport(layout.pos.col = 1, layout.pos.row = 2))
>> working trellis graph code here
>> pushviewport(viewport(layout.pos.col = 2, layout.pos.row = 1))
>> working trellis graph code here
>> pushviewport(viewport(layout.pos.col = 2, layout.pos.row = 2))
>> 
>> I'm obviously doing something wrong since my graphs still 
>print one per
>> page?
>
>Depends on the details of your 'working trellis code'. Are you using
>print() explicitly with 'newpage=FALSE'? See ?print.trellis for
>details.
>
>Deepayan
>
>> Would you be able to provide advice?
>> 
>> Thanks
>> 
>> Sam
>> ----
>> Sam McClatchie,
>> Biological oceanography
>> South Australian Aquatic Sciences Centre
>> PO Box 120, Henley Beach 5022
>> Adelaide, South Australia
>> email <mcclatchie.sam at saugov.sa.gov.au>
>> Telephone: (61-8) 8207 5448
>> FAX: (61-8) 8207 5481
>> Research home page <http://www.members.iinet.net.au/~s.mcclatchie/>
>> 
>>                    /\
>>       ...>><xX(°>
>>                 //// \\\\
>>                    <°)Xx><<
>>               /////  \\\\\\
>>                         ><(((°>
>>   >><(((°>   ...>><xX(°>O<°)Xx><<
>> 
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>http://www.R-project.org/posting-guide.html
>>
>




More information about the R-help mailing list