使用do.call和gridExtra重新排序ggplots列表(reorder list of ggplots using do.call and gridExtra)

我有一个ggplots列表,我创建的gglist包含ggplot1 , ggplot2和ggplot3 。 我想使用grid.arrange()来安排它们:

do.call(grid.arrange,gglist)

但是,我想重新排序,以便它们出现在序列ggplot3 , ggplot1和ggplot2 。 如何使用do.call函数执行此操作?

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?

最满意答案

您应该可以使用[c(your order)]重新排序存储在gglist中的图表的方式

在这种情况下:

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

如果你要指定图形的顺序,你甚至不必使用do.call ,只需使用grid.arrange函数,如:

grid.arrange(ggplot3, ggplot1, ggplot2)

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)

更多推荐