thomasp85 / patchwork

The Composer of ggplots
https://patchwork.data-imaginist.com
Other
2.46k stars 162 forks source link

Merge titles more aggressively #352

Closed teunbrand closed 2 months ago

teunbrand commented 7 months ago

This PR aims to fix #349.

Briefly, when merging titles, multi-cell titles are not taken into account. It allows cases such as the reprex from #349 to merge titles.

library(ggplot2)
devtools::load_all("~/packages/patchwork/")
#> ℹ Loading patchwork

p1 <- ggplot(mtcars) +
  geom_point(aes(mpg, disp)) +
  labs(y = "mpg", x = "collected axis title")

p2 <- ggplot(mtcars) +
  geom_boxplot(aes(gear, disp, group = gear)) +
  labs(y = "gear", x = "collected axis title")

p1 + p2 + plot_layout(axis_titles = "collect_x", design = "AAB")

However, this also means that titles are merged over multi-cell titles. In the plot below, the mpg label is not repeated for the 2nd column, which used to be the case. The changed snapshot is related to this.

plots <- wrap_plots(rep(list(p1), 3))
layout <- plot_layout(design = "12\n32", axis_titles = "collect")
plots + layout

Created on 2024-02-12 with reprex v2.1.0

I couldn't find an elegant solution to keep both cases working, but I think the tradeoff might be worth it.

thomasp85 commented 2 months ago

Thanks!