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

patchwork will get subscript out of bounds when using y axis on the right #340

Closed
smouksassi opened this issue Nov 30, 2023 · 1 comment
Closed

Comments

@smouksassi
Copy link

library(ggplot2)
library(patchwork)
library(egg)
#> Loading required package: gridExtra
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) +
  facet_grid(cyl~ vs,scales="free",switch="both",space = "free_x")+
  theme(strip.placement = "outside",
        axis.title.y.left = element_blank(),
        axis.title.x = element_blank(),
        strip.text.y.left = element_text(angle=0)) 
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))+
  facet_grid(cyl~ vs,scales="free",switch="both",space = "free_x")+
  scale_y_continuous( position = "left")+
  theme(strip.placement = "outside",
        axis.title.y.left = element_blank(),
        axis.title.x = element_blank(),
        strip.text.y.left = element_blank()) 

p1 + p2

p1 +(p2+ scale_y_continuous( position = "right"))
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.
#> Error in FUN(X[[i]], ...): subscript out of bounds

egg::ggarrange(p1 ,(p2+ scale_y_continuous( position = "right"))
, ncol =2)
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

workaround is to use egg ggarrange

Created on 2023-11-30 with reprex v2.0.2

@LukasWallrich
Copy link

(Deleted my comment as the similar faceting issue is fixed in the current version - this issue still occurs, though)

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