8

I have a list of ggplots from 1:10 called plot_1,plot_2....plot_10.

I wanted to use cowplot to display all plots together.

How can I use plot.grid() to call all plots? i.e I want to write something like

plot.grid(paste0("plot",1:10)) 

but this doesn't work - I get the error:

Error in ggplot_to_gtable(x) : Argument needs to be of class "ggplot" or "gtable"*

itzmurd4
  • 663
  • 10
  • 25
Birdonawire
  • 199
  • 3
  • 10

1 Answers1

13
plot_grid(plotlist=mget(paste0("pl_", 1:10)))

In the help information about plot_grid, it says you can use plotlist to provide a list of plots. The mget function gives you a way to search multiple objects by name (in this case the plots), which are generated by the paste0 function.

user3640617
  • 1,546
  • 13
  • 21