我想以以下方式规划三个情节:
[FirstPlot]
[2nd] [3rd]第一个情节位于第二个和第三个情节之上。第一幅是第二幅和第三幅的两倍。现在让我们生成虚拟数据:
library(gridExtra)
library(grid)
library(ggplot2)
library(lattice)
plot1 <- qplot(1, 1)
plot2 <- qplot(1, 1)
plot3 <- qplot(1, 1)
lay <- rbind(c(1,1),
c(2,3))绘制出来的语法应该是:
grid.arrange(grobs = c(plot1, plot2, plot3),
layout_matrix = lay)事实上,这不应该是因为它不起作用。我得到了以下错误。应该是什么命令才能把这一切都画出来?我想我搞错了grobs的部分。
t:b : NA/NaN参数错误
发布于 2018-01-24 21:22:54
grobs参数需要list()而不是c():
grid.arrange(grobs = list(plot1, plot2, plot3),
layout_matrix = lay)?grid.arrangegrobs的列表
发布于 2018-01-24 21:34:26
我想提供一个patchwork解决方案,因为它是一个非常酷的包:
library(patchwork)
library(ggplot2)
plot1 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
plot2 <- ggplot(diamonds, aes(cut, price)) + geom_boxplot()
plot3 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point()
# One way of doing it
plot1 + (plot2 + plot3) + plot_layout(ncol = 1)
# Another, alternative solution
plot1 /
(plot2 | plot3)返回:

发布于 2018-01-24 21:24:37
有个简单的解决办法。使用grobs = list(plot1, plot2, plot3)
https://stackoverflow.com/questions/48431758
复制相似问题