Bon*_*ono 6 r list ggplot2 gridextra r-grid
我想ggplot2从列表中创建多个绘图,grid.arrange但是在按行排列之前按行排列.
gg_list1 <- list(qplot(mpg, disp, data = mtcars),
qplot(hp, wt, data = mtcars),
qplot(qsec, wt, data = mtcars))
gg_list2 <- list(qplot(mpg, disp, data = mtcars),
qplot(hp, wt, data = mtcars),
qplot(qsec, wt, data = mtcars))
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样做:
do.call(grid.arrange,c(gg_list1,gg_list2 , ncol = 2, nrow = 3))
Run Code Online (Sandbox Code Playgroud)
但它从上到下从左到右填充.
我试过这个:
do.call(grid.arrange, c(gg_list1, arrangeGrob(gg_list2, nrow = 3), ncol = 2))
Run Code Online (Sandbox Code Playgroud)
但是得到 Error: length(widths) == ncol is not TRUE
有任何想法吗?
ali*_*ire 10
你可以使用grobs参数来传递一个列表和as.table参数来逐列填充,所以c你需要的就是扁平化
grid.arrange(grobs = c(gg_list1, gg_list2), ncol = 2, as.table = FALSE)
Run Code Online (Sandbox Code Playgroud)
如果您想要更复杂的布局,请使用以下layout_matrix参数:
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)
Run Code Online (Sandbox Code Playgroud)
见的arrangeGrob小插曲了解详情.
| 归档时间: |
|
| 查看次数: |
4827 次 |
| 最近记录: |