joel.wilson
joel.wilson

Reputation: 8413

R : How to increase height of grid.arrange

Is there a way to increase the space for plotting when making a unbalanced grid of plots. See the below, where max area is unutilised.

library(gridExtra) 
p <- ggplot(data = mtcars)+geom_point(aes(x=mpg,y=mpg))
grid.arrange(p, arrangeGrob(p,p,
                       p,p, 
                       heights = c(1/1.5,1/1.5),nrow=2),
         nrow=3,heights=c(1,1.2,1.2))

enter image description here

Upvotes: 0

Views: 5627

Answers (2)

user9469977
user9469977

Reputation: 11

grid.arrange(p,p,p,p,p, layout_matrix = matrix(c(1,1:5), ncol=2, byrow=TRUE))

Upvotes: 1

Tung
Tung

Reputation: 28371

Solution using patchwork package

library(ggplot2)
library(patchwork)

p <- ggplot(data = mtcars) + geom_point(aes(x = mpg, y = mpg))

p / {
   p + {p} + plot_layout(ncol = 2)
 } / {
   p + {p} + plot_layout(ncol = 2)
 } + 
 plot_layout(nrow = 3, widths = c(1, 1.2, 1.2))

Created on 2018-03-09 by the reprex package (v0.2.0).

Upvotes: 1

Related Questions