Assign grid.arrange to object
Posted
by
Tyler Rinker
on Stack Overflow
See other posts from Stack Overflow
or by Tyler Rinker
Published on 2013-11-07T03:38:50Z
Indexed on
2013/11/07
3:54 UTC
Read the original article
Hit count: 170
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.
© Stack Overflow or respective owner