Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use grid.arrange over multiple pages or marrangeGrob with a layout_matrix

i want to arrange plots with the following layout_matrix over multiple pages.

enter image description here

rep. e.g.

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)

pls help me with a general solution to have a layout_matrix on multiple pages.

like image 235
Andre Elrico Avatar asked Mar 09 '23 07:03

Andre Elrico


1 Answers

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.

like image 153
baptiste Avatar answered Mar 12 '23 14:03

baptiste