rggplot2patchwork

Combine three plots keeping same width with patchwork


I am trying to combine three plots, and I would like to have one plot on top and two in a second row one next to the other. All plots should have same height and width. I am using patchwork package. However, with the solution I found, the two bottom plots still seem to have different width. Any suggestion on how to proceed? Below you can find a reproducible example that shows what I mean:

library(tidyverse)
library(patchwork)

data("iris")

plot1 <- iris %>% 
  ggplot(aes(x = Species, y = Sepal.Length)) +
  geom_point()

design <- "#AA#
           BBCC"

plot_comb <- plot1 + plot1 + plot1 + 
  plot_annotation(tag_levels = "A") + plot_layout(design = design) & 
  theme(plot.tag = element_text(face = "bold"))

plot_comb

Thank you in advance!


Solution

  • I admit to not knowing exactly why this is necessary for three identical plots, I find the use of free(.) helpful when I need to strong-arm some alignment attempts (that are normally very welcome).

    Your code for me produces:

    original ggplot2, bottom right plot has a different width as the other two despite being the sample underlying grob

    plot_comb <- free(plot1) + free(plot1) + free(plot1) + 
      plot_annotation(tag_levels = "A") + plot_layout(design = design) & 
      theme(plot.tag = element_text(face = "bold"))
    plot_comb
    

    same three-graph combined plot, all the same width