rggplot2patchwork

Patchwork not following layout correctly


I want four equally sized panels on the second row of my plot but the output is not matching the layout I specify.

library(ggplot2)
library(patchwork)

set.seed(1)
df<-data.frame(x=rnorm(10),y=rnorm(10))
p <- ggplot(df, aes(x=x,y=y)) +
  geom_point()

layout <- "
AAABBBBB
CCDDEEFF
"

p + p + p + p + p + p + plot_layout(design = layout)

enter image description here


Solution

  • This will produce the correct output (adapted from here)

    (p + p + plot_layout(widths = c(3,5))) /
      (p + p + p +p + plot_layout(widths = c(2,2,2,2)))