patchwork
patchwork copied to clipboard
Alignment difficulties with `theme(strip.placement = "outside")`
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
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)
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