Is there a way to add titles by row or column using the patchwork package for combining plots? Ex. with the arrangement : patchwork<- (p| p2 | p3)/ (p4| p5| p6), I would like one title for plots 1-3 and another for 4-6.
Asked
Active
Viewed 959 times
10
-
I think this could be achievable by using [tagging](https://patchwork.data-imaginist.com/articles/guides/annotation.html) – stevec May 06 '20 at 17:32
-
I could think of three workarounds: **(1)** setting the plot titles/axis labels in ggplot directly (and omit some) can create the impression of overarching axis labels, **(2)** Using ggplot's [facet_wrap](https://ggplot2.tidyverse.org/reference/facet_wrap.html) can be an option as that has overarching row/column titles (but only if your data structure works with facet_wrap). **(3)** A ["grob"](https://community.rstudio.com/t/common-axis-title-in-grid-arrange/96353) instead of patchwork might help. But often found myself needing to use Powerpoint/Illustrator. – Tapper Jan 19 '22 at 21:42
1 Answers
1
Yes, there is a way to put labels for rows or columns in arrangements of plots generated with patchwork
by using a textGrob
as suggested by in one of the comments:
p1 <- ggplot(iris, aes(x=Species,y=Petal.Length)) + geom_boxplot()
p2 <- ggplot(iris, aes(x=Species,y=Sepal.Length)) + geom_boxplot()
row_label_1 <- wrap_elements(panel = textGrob('First Row', rot=90))
row_label_2 <- wrap_elements(panel = textGrob('First Row', rot=90))
p_all <- (row_label_1 | p1 | p2) / (row_label_2 | p1| p2) +
plot_layout(widths = c(.1,1,1)) # adjust with

NicolasBourbaki
- 853
- 1
- 6
- 19