Bonono
Bonono

Reputation: 847

reorder list of ggplots using do.call and gridExtra

I have a list of ggplots that I've created as gglistthat contain ggplot1, ggplot2 and ggplot3. I want to arrange them using grid.arrange() as such:

do.call(grid.arrange,gglist)

However, I want to reorder so that they appear in the sequence ggplot3, ggplot1an ggplot2. How do I do that with the do.call function?

Upvotes: 1

Views: 98

Answers (1)

Yang Li
Yang Li

Reputation: 482

You should be able to reorder how the graphs stored in gglist come in by using [c(your order)]

In this case:

do.call(grid.arrange, gglist[c(3,1,2)])

If you're specifying the order of the graphs, you do not even have to use do.call and just use the grid.arrange function normally like:

grid.arrange(ggplot3, ggplot1, ggplot2)

Upvotes: 4

Related Questions