How to specify tagging levels when using textual layout in patchwork package?

I want to tag the plots: A1, A2, B. I can get A-C and A1-A3 but not what I am after, what am I missing?

#Grid layout

grid <- "

AABB

CCCC

"

#the following tags A-C

patchwork <- p1 + p2 + p3 +

plot_layout(design = grid, guides = "collect", tag_level = 'new')

patchwork + plot_annotation(tag_levels = c("A","1"))

#the followign tags A1- A3

wrap_plots(p1 + p2 + p3 +

plot_layout(design = grid, guides = "collect", tag_level = 'new'))

#data:

p1 <- ggplot(mpg) +

geom_point(aes(x = displ, y = hwy))

p2 <- ggplot(mpg) +

geom_bar(aes(x = as.character(year), fill = drv), position = "dodge") +

labs(x = "year")

p3 <- ggplot(mpg) +

geom_density(aes(x = hwy, fill = drv), colour = NA) +

facet_grid(rows = vars(drv))

p4 <- ggplot(mpg) +

stat_summary(aes(x = drv, y = hwy, fill = drv), geom = "col", fun.data = mean_se) +

stat_summary(aes(x = drv, y = hwy), geom = "errorbar", fun.data = mean_se, width = 0.5)

If you want some special tagging of plots within a patchwork that isn't possible to do using the plot_annotation() function, it is probably easiest to just specify the tags manually via labs(tag = ...). This is what patchwork is doing under the hood.

library(ggplot2)
library(patchwork)

p1 <- ggplot(mpg) +
  geom_point(aes(x = displ, y = hwy)) +
  labs(tag = 'A1')

p2 <- ggplot(mpg) +
  geom_bar(aes(x = as.character(year), fill = drv), position = "dodge") +
  labs(x = "year", tag = 'A2')

p3 <- ggplot(mpg) +
  geom_density(aes(x = hwy, fill = drv), colour = NA) +
  labs(tag = 'B') +
  facet_grid(rows = vars(drv))

(p1 | p2) / p3

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.