patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

Alignment difficulties with `theme(strip.placement = "outside")`

Open davidhodge931 opened this issue 7 months ago • 1 comments

Likewise strip.placement.x and strip.placement.y

library(patchwork)
library(tidyverse)

set_theme(theme_classic() + theme(strip.placement = "outside"))

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl)

p1 / (p3 | p2)

Created on 2025-08-26 with reprex v2.1.1

davidhodge931 avatar Aug 26 '25 01:08 davidhodge931

I’ve developed a new approach in the ggalign package for plot alignment that can handle different strip placements, as demonstrated below:

library(ggalign)
p0 <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~"foo", strip.position = "bottom") +
  theme(strip.placement = "inside", strip.text = element_text(size = 20))
p1 <- p0 + theme(strip.placement = "outside")
alignpatches(p0, p1)
Image

I apologize that it is not feasible to integrate this directly into the patchwork package, as it would require significant refactoring of existing code—something that was previously declined in issue #379

Yunuuuu avatar Oct 22 '25 05:10 Yunuuuu