i want to arrange plots with the following layout_matrix over multiple pages.
library(gridExtra)
library(ggplot2)
layout <- rbind(c(1,2,3,4),
c(1,2,3,4),
c(1,2,3,4),
c(5,5,5,5))
p <- list()
for(i in 1:15) {
ifelse(i %% 5 > 0,
p[[i]] <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + ggtitle(paste("plot:",i)),
p[[i]] <- tableGrob(mtcars[5:7,],rows = NULL)
)
}
if i have only one page: (easy)
grid.arrange(grobs=p[1:5],layout_matrix=layout)
if i want multiple pages: (i loose all my pattern)
marrangeGrob(grobs=p,nrow=4,ncol=2)
this seems to work,
marrangeGrob(grobs=p, nrow=1, ncol=5, layout_matrix=layout)
(admittedly by chance)
marrangeGrob
is just a thin wrapper around a for loop and grid.arrange, so in case you need something more refined than this lucky workaround you should probably modify the code to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With