You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
Hello, thanks for your work on this very helpful package!
I'm using patchwork v1.1.3 (with ggplot2 v3.4.0) and have found that this bug persists when faceting is used on both the plots. The bug occurs with either a vertical or horizontal plot layout and I can confirm that I can run the minimum reproducible example above without triggering the original bug.
I've updated the minimum reproducible example to show the new scenario for the bug. Thank you for looking into this.
## Generate demo data
df = data.frame(
inc = rep(1:10,3),
prev = rnorm(30),
grp_1 = rep(c("a","b","c"),each=10),
grp_2 = sample(c("x","y","z"),size=30,replace=TRUE)
)
## Generate the main plot elements
#p1.a: Create the left column, which only facets on grp_1, giving a 'total' column of plot panels
#p2.a: Create the right column, which facets on grp_1 AND grp_2
plot_base = ggplot(df,aes(x = inc, y = prev, color = grp_1)) + geom_point()+guides(color="none")
p1.a = plot_base+ facet_grid(rows=vars(grp_1),switch="y")
p2.a = plot_base+ facet_grid(cols=vars(grp_2),rows=vars(grp_1))
#Generate plot (x-axis text/ticks are as expected)
p1.a|p2.a
#Change strip placement
p1.b = p1.a+ theme(strip.placement = "outside")
#Re-generate plot with strip outside (x-axis text/ticks are as shifted for p2.a)
p1.b|p2.a
See also the figure output for the p1.b|p2.a patchwork:
If one tries to stack two plots patchwork and one of the plots uses
facet_grid
andtheme(strip.placement = "outside")
, this messes up the placement of tick marks.Minimal reproducible example
The following works as expected:
Now modify plot
p2.a
and stack again: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 needtheme(strip.placement = "outside")
to manage the position of tick marks after usingscale_y_continuous(sec.axis = dup_axis())
, which I have omitted from the example.The text was updated successfully, but these errors were encountered: