PowerOld9540
PowerOld9540

Reputation: 75

Efficient way to plot multiple ggplots from list using gridextra?

I have generated a list containing 25 ggplot elements and I want to plot them all on one page. Since I couldn't find a way to use par() for ggplots, I used the package gridextra and specifically the function grid.arrange().

It comes in less handy than par() for base-R plots....My attempt was the following and I wonder if there is a more efficient way to write it?

Thanks in advance!

plot_collection <- grid.arrange(DBScan_plots[[1]], DBScan_plots[[2]], DBScan_plots[[3]], DBScan_plots[[4]], DBScan_plots[[5]], 
                                DBScan_plots[[6]], DBScan_plots[[7]], DBScan_plots[[8]], DBScan_plots[[9]], DBScan_plots[[10]], 
                                DBScan_plots[[11]], DBScan_plots[[12]], DBScan_plots[[13]], DBScan_plots[[14]], DBScan_plots[[15]], 
                                DBScan_plots[[16]], DBScan_plots[[17]], DBScan_plots[[18]], DBScan_plots[[19]], DBScan_plots[[20]], 
                                DBScan_plots[[21]], DBScan_plots[[22]], DBScan_plots[[23]], DBScan_plots[[24]], DBScan_plots[[25]], 
                                nrow = 5,
                                ncol = 5)

Upvotes: 0

Views: 1273

Answers (1)

ljwharbers
ljwharbers

Reputation: 393

grid.arrange works with lists of plots. Just specify it with grobs = .

In your case:

plot_collection <- grid.arrange(grobs = DBScan_plots, nrow = 5, ncol = 5)

Upvotes: 1

Related Questions