我想将几个 ggplot2 图表组合成一个使用cowplot::plot_grid()
. 从其文档中:
?plot
Arguments
...
List of plots to be arranged into the grid. The plots can be objects of one of the following classes: ggplot, recordedplot, gtable, or alternative can be a function creating a plot when called (see examples).
所以,如果我输入一个 ggplot2 对象列表plot_grid()
,它应该将这些图合并为一个,对吗?
那么为什么这行不通呢?
p1 <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
p2 <- ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
theme(axis.text.x = element_text(angle=70, vjust=0.5))
list(p1, p2) %>%
map(plot_grid)