[R] Ggplot2: saving a grid with multiple plots

Dieter Menne dieter.menne at menne-biomed.de
Thu Mar 12 09:03:31 CET 2009


ONKELINX, Thierry <Thierry.ONKELINX <at> inbo.be> writes:

> I have managed to create a figure on the screen with multiple plots in
> it. Something like the example below. When I save that with ggsave(),
> only the last plot gets saved (pPath in the example) instead of the
> entire figure. Any suggestions how I can save this kind of figures
> automated?

No idea what the easiest way would be if you want both window and 
pdf.

Dieter

library(ggplot2)
pPoint <- qplot(unemploy/pop, psavert, data=economics)
pPath <- qplot(unemploy/pop, psavert, data=economics, geom="path")

pdf(file="test.pdf")
pushViewport(viewport(layout = grid.layout(2, 1)))
print(pPoint, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(pPath, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
dev.off()




More information about the R-help mailing list