Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggbreak does not work properly with facet_grid #55

Open
whzemuch opened this issue Sep 30, 2022 · 1 comment
Open

ggbreak does not work properly with facet_grid #55

whzemuch opened this issue Sep 30, 2022 · 1 comment

Comments

@whzemuch
Copy link

@xiangpin @GuangchuangYu

The ggbreak package works perfectly with facet_wrap! However, the order of the subplots is not correct when working with facet_grid. Please check the example below( adapted from the ggbreak online vignettes with some modifications),.

For example, the subplots labeled as C should be put together in the attached plot, but they are separated when using either function(scale_y_break in middle plot and scale_y_cut in right plot). I guess that you can change the algorithm to arrange the order of the subplots when working with facet_grid.

library(ggplot)
library(aplot)
library(ggbreak)




set.seed(2019-01-19)
d <- data.frame(
  x = 1:20,
  y = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22),
  group = c(rep("A", 10), rep("B", 10)),
  face=c(rep("C", 5), rep("D", 5), rep("C", 5), rep("D", 5))
)

p <- ggplot(d, aes(x=x, y=y)) +
     geom_col(orientation="x") +
     scale_y_reverse() +
     facet_wrap(group~.,
                scales="free_y",
                strip.position="right",
                nrow=2
                ) +
     coord_flip() +
     theme_bw()

plot1 <-  p + scale_y_break(c(7, 17), scales="free") 

 p1 <- ggplot(d, aes(x=x, y=y)) +
         geom_col(orientation="x") +
         scale_y_reverse() +
        facet_grid(group~face) +
        coord_flip() +
        theme_bw()
 
plot2 <-  p1 + scale_y_break(c(7, 17), scales="free")  
plot3 <- p1 + scale_y_cut(breaks = c(7, 17), which = c(1, 1), scales = c(1, 2))
     
aplot::plot_list(plot1,  plot2, plot3 )

image

@joybaker1
Copy link

I actually have similar questions and I tried to generate a list of plots with breaks and arrange it myself. But the breaks disappear in aplot::plot_list, cowplot::plot_grid, patchwork:wrap_plots and gridExtra::grid.arrange. Anyone have solutions how to work with ggbreak() for a combinned individual plots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants