Here is a simplified version of an issue I encountered:
grob.list <- vector("list", length = 2)
for (i in 1:2) {
grob.list[[i]] <- qplot(1:5, 1:5 * (-1)^i)
}
grid.arrange(grobs = grob.list)
We get two of the same graph (grob.list[[1]]
is wrong).
If we print (even invisibly) the grobs turn out correctly.
grob.list <- vector("list", length = 2)
for (i in 1:2) {
grob.list[[i]] <- qplot(1:5, 1:5 * (-1)^i)
invisible(print(grob.list[[i]]))
}
grid.arrange(grobs = grob.list)
So does printing forces a ggplot object to "settle"? What does printing a ggplot object actually change to it?
Seems related to Grid of multiple ggplot2 plots which have been made in a for loop but doesn't address what printing does.