Assign grid.arrange to object
- by Tyler Rinker
I want to arrange plots with grid.arrange to make more complex coplots and then use grid.arrange to combine these complex coplots. I am using the following solution (http://stackoverflow.com/a/13295880/1000343) in this task to arrange mutliple plots and ensure they have equal widths. Here is a demo of the code:
library(ggplot2); library(gridExtra)
gA <- ggplotGrob(A)
gB <- ggplotGrob(B)
maxWidth = grid::unit.pmax(gA$widths[2:5], gB$widths[2:5])
gA$widths[2:5] <- as.list(maxWidth)
gB$widths[2:5] <- as.list(maxWidth)
x <- grid.arrange(gA, gB, ncol=1)
y <- grid.arrange(gA, gB, ncol=1)
grid.arrange(x, y, ncol=2)
To be clear in my case x and y are slightly different plots with different values. I know grid.arrange isn't returning the plot as other grid based functions.