I am trying to arrange base and grid plots. Looking at this post I thought I had it but it appears that calling the same code several times in a row is breaking it.
Here is a reproducible example
library(grid)
library(gridBase)
library(gridExtra)
pdf('test.pdf')
for(i in 1:11){
layout(matrix(c(1,3, 2,3, 4,3), nrow = 3, ncol = 2, byrow = TRUE))
# First base plot
plot(1:10)
# second base plot
plot.new()
# Grid regions of current base plot (ie from frame)
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
# Table grob
grob <- tableGrob(iris[1:2,1:2])
grid.draw(grob)
popViewport(3)
# third base plot
plot(1:10)
# fourth
plot.new()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
grid.draw(grob)
}
graphics.off()
I's expect the plots to be composed of 11 equivalent pages but the grid are all over the place:
page1 is ok:
page2 and >2 are not:
page3:
What can I do to get a proper 10 pages document. I happen to call a ploting routine several times with slightly different data so I expect to get something consistent across calls