Bug when using horizontal stacking for plots with theme(strip.placement = "outside")
If one tries to stack two plots patchwork and one of the plots uses facet_grid and theme(strip.placement = "outside"), this messes up the placement of tick marks.
Minimal reproducible example
The following works as expected:
df =
data.frame(
inc = rep(1:10,3),
prev = rnorm(30),
grp = rep(c("a","b","x"),each=10)
)
p1 = ggplot(df,aes(x = inc, y = prev, color = grp)) + geom_point()
p2.a = ggplot(df,aes(x = inc, y = prev, color = grp)) +
geom_point() +
facet_grid(~grp)
p1 / p2.a
Now modify plot p2.a and stack again:
p2.b = p2.a + theme(strip.placement = "outside")
p1 / p2.b
In the second plot, y-ticks marks and labels and y-label of the top plot are be moved to the right, so that the y-tick labels of the top plot are horizontally aligned with the y-label of the bottom plot. See also this figure.

Note: For this minimally reproducible example theme(strip.placement = "outside") does not change the plot. In my application I need theme(strip.placement = "outside") to manage the position of tick marks after using scale_y_continuous(sec.axis = dup_axis()), which I have omitted from the example.