Hi:
recordPlot() isn't going to work with grid graphics, I don't think. I
can confirm that your way doesn't produce three graphs on a page using
grid. I also tried the grid.arrange() function in the gridExtra
package, and that turned out to be illuminating. Note that
recordPlot() comes from the grDevices package in base R.
set.seed(1410)
dsmall=diamonds[sample(nrow(diamonds),100),]
qplot(carat,price,data=dsmall,geom=c("point"))
a=recordPlot()
b=recordPlot()
c=recordPlot()
library('grid')
grid.newpage()
pushViewport(viewport(layout=grid.layout(4,2)))
vplayout=function(x,y)
viewport(layout.pos.row=x,layout.pos.col=y)
print(a,vp=vplayout(1:2,1))
print(b,vp=vplayout(1:2,2))
print(c,vp=vplayout(3:4,1))
As I'm sure you found, this renders one graph at a time, each of which
takes up a complete graphics page. You could say that the graphs are
'grid-unaware'. Trying this with gridExtra,
library('gridExtra')
grid.arrange(a, b, c, ncol = 2)
Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main, :
input must be grobs!
...which tells you that the output of recordPlot() does not yield
grobs that the grid package can recognize.
OTOH, if you do
a <- qplot(carat,price,data=dsmall,geom=c("point"))
b <- qplot(carat,price,data=dsmall,geom=c("point"))
c <- qplot(carat,price,data=dsmall,geom=c("point"))
and use the code above, both will print as expected because a ggplot
graphic is a grob (graphical object). It seems that what you need is a
way to edit/modify your plots in order to return grobs with which the
grid package can work. Perhaps the grid experts on this list can
provide more specific details.
HTH,
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2