Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cowplot for a list of plots using paste0

Tags:

r

paste

cowplot

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

like image 444
Birdonawire Avatar asked Dec 23 '22 15:12

Birdonawire


1 Answers

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.

like image 168
user3640617 Avatar answered Jan 13 '23 02:01

user3640617