Reputation: 319
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"*
Upvotes: 8
Views: 7970
Reputation: 1576
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.
Upvotes: 14