Search code examples
rggplot2labellegendpatchwork

How to show the tags of an array of ggplots made with the patchwork package?


I have 5 plots that I want to organize in 2 columns: the first with 2 plots and the second with 3 plots. I used the patchwork package and the arrangement was the way I want it, but the tags don't appear even though I declared them in the plot_annotation command.

library(ggplot2)
library(patchwork)

p <- ggplot()

plots <- (p/p)|(p/p/p) +
  plot_annotation(tag_levels = "a")
plots

enter image description here

If I modify the layout, the tags appear. Note that when changing | by + tags appear

plots <- (p/p)+(p/p/p) +
  plot_annotation(tag_levels = "a")
plots

enter image description here

Any help?


Solution

  • We need to wrap all plots before annotation:

    ((p/p)|(p/p/p)) +
      plot_annotation(tag_levels = "a")
    

    enter image description here