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

2009-05-15 Thread Sebastien . Bihorel
Hi Deepayan,

Thank you very much for the tip. After removing the 'more' argument and
another couple of hours, I finally found something that works for my
multi-page multi-graph plots. For documentation, the script is:


library(lattice)
library(grid)

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

# Defines some viewports
fulldevice - viewport(x=0, y=0, width=1, height=1, just=c(0,0),
name=fulldevice)
plotvw - viewport(x=0, y=0, width=1, height=0.95, just=c(0,0),
name=plotvw)
titlevw - viewport(x=0, y=0.95, width=1, height=0.05, just=c(0,0),
name=titlevw)
tree - vpTree(fulldevice,vpList(plotvw,titlevw))

for (i in 1:4) {
  plots - xyplot((i*y)~x,data=foo)

  grid.newpage()
  pushViewport(tree)

  seekViewport(plotvw)

  print(plots, split=c(1,1,2,4), newpage=FALSE)
  print(plots, split=c(2,1,2,4), newpage=FALSE)
  print(plots, split=c(1,2,2,4), newpage=FALSE)
  print(plots, split=c(2,2,2,4), newpage=FALSE)
  print(plots, split=c(1,3,2,4), newpage=FALSE)
  print(plots, split=c(2,3,2,4), newpage=FALSE)
  print(plots, split=c(1,4,2,4), newpage=FALSE)
  print(plots, split=c(2,4,2,4), newpage=FALSE)


  seekViewport(titlevw)

  grid.text(label = test,
just = c(centre,centre),
gp = gpar(fontsize = 10, font = 2))
}



 On Thu, May 14, 2009 at 1:58 PM, Sebastien Bihorel
 sebastien.biho...@cognigencorp.com wrote:
 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.

 Without looking at it in detail, here's one bit of advice that might
 help: if you are using pushViewport(), don't use 'more', use only
 'newpage', and preferably don't use 'split' either. In particular, if
 you are using 'more', the first print.trellis() call will always start
 a new page, and your viewport will be lost.

 -Deepayan


 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.biho...@cognigencorp.com
 mailto:sebastien.biho...@cognigencorp.com
 Phone: (716) 633-3463 ext. 323

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-05-14 Thread Sebastien Bihorel

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.biho...@cognigencorp.com 
mailto:sebastien.biho...@cognigencorp.com

Phone: (716) 633-3463 ext. 323

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-05-14 Thread Deepayan Sarkar
On Thu, May 14, 2009 at 1:58 PM, Sebastien Bihorel
sebastien.biho...@cognigencorp.com wrote:
 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.

Without looking at it in detail, here's one bit of advice that might
help: if you are using pushViewport(), don't use 'more', use only
'newpage', and preferably don't use 'split' either. In particular, if
you are using 'more', the first print.trellis() call will always start
a new page, and your viewport will be lost.

-Deepayan


 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.biho...@cognigencorp.com
 mailto:sebastien.biho...@cognigencorp.com
 Phone: (716) 633-3463 ext. 323

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.