YuLab-SMU / ggbreak

:broken_heart: An implementation of scale functions for setting axis breaks of a 'gg' plot.
https://www.frontiersin.org/articles/10.3389/fgene.2021.774846
131 stars 4 forks source link

Misaliged plots when using patchwork #46

Open antgon opened 2 years ago

antgon commented 2 years ago

If a "broken" plot is combined with other plots using patchwork the axes are misaligned, e.g.:

library(tidyverse)
library(ggbreak)
library(patchwork)

df <- tibble( x = seq(0, 2*pi, 0.01),
    y1 = sin(x),
    y2 = sin(x * 2) + 100)

plt1 <- ggplot(df, aes(x, y1)) + geom_line()
plt2 <- plt1 + scale_x_break(c(1, 3), expand = F)
plt3 <- ggplot(df, aes(x, y2)) + geom_line()

(plt2 + plt1) / (plt1 + plt3)
# Same with plot_layout, as in
# plt2 + plt1 + plt1 + plt3 + plot_layout(nrow=2)

Screenshot from 2022-03-29 18-08-59


Incidentally, if I try to combine the same plots with cowplot instead of patchwork, the ggbreak::scale_x_break layer disappears:

library(cowplot)
plot_grid(plt2, plt1, plt1, plt3, nrow=2, align="hv")

Screenshot from 2022-03-29 18-22-43

cjpratt94 commented 2 months ago

I would like to second the above issues