From https://stackoverflow.com/a/3129691/ I learned how to organize two plots with lined plot areas.
My question is: how can I get an object of stacked graphs?
Example:
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)
source share