grid.arrange ggplot2 plots by columns instead of by row using lists

后端 未结 1 1481
悲哀的现实
悲哀的现实 2021-01-05 01:59

I want create a multiplot of ggplot2 plots from a list using grid.arrange but arrange them by columns before doing it by rows.

gg_l         


        
相关标签:
1条回答
  • 2021-01-05 02:40

    You can use the grobs parameter to pass a list and the as.table parameter to fill column-wise, so flattened with c, all you need is

    grid.arrange(grobs = c(gg_list1, gg_list2), ncol = 2, as.table = FALSE)
    

    If you want a more complex layout, use the layout_matrix parameter:

    my_layout <- rbind(c(1, 1:3, 4), c(1, 1:3, 4), c(1, 1:3, 5), c(1, 1:3, 6))
    
    my_layout
    ##      [,1] [,2] [,3] [,4] [,5]
    ## [1,]    1    1    2    3    4
    ## [2,]    1    1    2    3    4
    ## [3,]    1    1    2    3    5
    ## [4,]    1    1    2    3    6
    
    grid.arrange(grobs = c(gg_list1, gg_list2), layout_matrix = my_layout)
    

    See the arrangeGrob vignette for details.

    0 讨论(0)
提交回复
热议问题