I try to arrange two ggplots with different plot heights but same plot widths using the gridExtra package.
I have a solution for either the same width or the same height but I am unable to achieve both.
Here is my code:
require(ggplot2)
require(gridExtra)
set.seed(987)
dat <- data.frame(x = 1:100,
y1 = rnorm(100),
y2 = rnorm(100)*1e6)
p1 <- ggplot(dat, aes(x = x, y = y1)) +
geom_point() + ylab("")
p2 <- ggplot(dat, aes(x = x, y = y2)) +
geom_point() + ylab("")
# Arrange Plots
# Version 1
# same widths, same heights
grid.draw(rbind(ggplotGrob(p1), ggplotGrob(p2), size = "last"))
# Version 2
# different heights, different widths
grid.arrange(p1, p2, ncol = 1, heights = c(2, 1))
Which results in this:
Version 1: Same widths but not different heights
Version 2: Different heights but not same plot widths
However, I want to have the combination: Same width, but different heights. Do you have any ideas of how to combine grid.draw and grid.arrange in this case?