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"*
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.
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