我从https://dev59.com/ImYr5IYBdhLWcg3w6eQ3#13295880了解到如何排列两个具有对齐绘图区域的图表。
我的问题是:如何获取排列好的图表对象?
示例:
require(ggplot2)
require(gridExtra)
A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +coord_flip()
B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip()
gA <- ggplot_gtable(ggplot_build(A))
gB <- ggplot_gtable(ggplot_build(B))
maxWidth = grid::unit.pmax(gA$widths[2:3], gB$widths[2:3])
gA$widths[2:3] <- as.list(maxWidth)
gB$widths[2:3] <- as.list(maxWidth)
## works:
grid.arrange(gA, gB, ncol=1)
## does not work:
theplot <- grid.arrange(gA, gB, ncol=1, plot=FALSE)
返回一个框架 grob;如果 plot=T,则会产生副作用(绘图)
。 - Andreasgrid.arrange
函数也会以不可见的方式返回grob
对象。 - baptiste