Hi

On 05/24/13 20:24, Johannes Graumann wrote:
Hi,

I'm currently combining multiple plots using something along the lines
of the following pseudo-code:

library(grid)
grid.newpage()
tmpLayout <- grid.layout(
     nrow=4,
     ncol=2)
pushViewport(viewport(layout = tmpLayout))

and than proceeding with filling the viewports ... works fine, but for
packaging of functions I would really prefer if I could assemble all of
this in an object which in the end would be callable with "print".

I'm envisioning something along the lines of what I can do with
ggplot2: return a plot as a ggpplot object and plot it later rather
than as I assemble it. Is that possible with a complex grid figure?

Thanks for any pointers.

You can work off-screen with grobs and gTrees and vpTrees, for example ...

library(grid)
vplay <- viewport(layout=grid.layout(2, 2),
                  name="vplay")
vp.1.1 <- viewport(layout.pos.col=1, layout.pos.row=1,
                   name="vp.1.1")
vp.2.2 <- viewport(layout.pos.col=2, layout.pos.row=2,
                   name="vp.2.2")
x <- gTree(childrenvp=vpTree(vplay, vpList(vp.1.1, vp.2.2)),
           children=gList(
               rectGrob(vp="vplay::vp.1.1", gp=gpar(fill="grey")),
               textGrob("1", vp="vplay::vp.1.1"),
               rectGrob(vp="vplay::vp.2.2", gp=gpar(fill="grey")),
               textGrob("2", vp="vplay::vp.2.2")))
grid.newpage()
grid.draw(x)

... is that the sort of thing you mean?

Paul

Joh

______________________________________________
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.


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
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.

Reply via email to