I'd like to arrange a 3x3 grid layout over 3 pages of a PDF file. I'd like to plot in arbitrary grid locations across the three pages. I know how to arrange multiple subplots using some option like layout=c(3,3)
. I can figure out how to arrange a 3x3 layout on a single plot using the grid package, and then decide to choose which plot to use. However, I can't figure out how to lay out a 3x3 grid over 3 pages, and then choose which grid to plot in.
I was hoping grid.newpage()
would solve my problem, as in the following:
library(grid)
pdf(file="griddtest.pdf",paper="letter")
vp1 <- viewport(x = 0, y = 0.5, w = 0.5, h = 0.5, just = c("left", "bottom"),
name = "vp1")
vp2 <- viewport(x = 0, y = 0.5, w = 0.5, h = 0.5, just = c("left", "bottom"),
name = "vp2")
pushViewport(vp1)
grid.text("Some drawing in graphics region 1 on page 1",y = 0.8)
grid.newpage()
pushViewport(vp2)
grid.text("Some drawing in graphics region 2 on page 2",y = 0.8)
dev.off()
but this just generates the second page (I'm guessing 'newpage' overwrites the oldpage, rather than making a new page).
Any help would be greatly appreciated!