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

Error when using theme(strip.placement = 'outside') to create layouts #325

Closed
TanyaS08 opened this issue Jun 2, 2023 · 0 comments
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@TanyaS08
Copy link

TanyaS08 commented Jun 2, 2023

Hi, thanks so much for the awesome package!

When using theme(strip.placement = 'outside') for plots its seems to be throwing errors when trying to patchwork more complex layouts, it throws the following error message Error in FUN(X[[i]], ...) : subscript out of bounds

As a minimum working example I'll create two of the same plots with the exception that p1 has a theme(strip.placement = 'outside') call

library(ggplot2)
library(patchwork)

p1 = ggplot(mpg, aes(displ, hwy, colour = class)) + 
  geom_point() +
  facet_grid(rows = vars(year),
             cols = vars(class),
             switch = 'y') +
  theme(strip.placement = 'outside')

p2 = ggplot(mpg, aes(displ, hwy, colour = class)) + 
  geom_point() +
  facet_grid(rows = vars(year),
             cols = vars(class),
             switch = 'y')

If I want to combine p1 + p2 I get the above error message. However p2 + p2 behaves as expected

I had initially discovered the bug when trying to use inset_element() where the base plot is the one with the theme(strip.placement = 'outside') call so in this case p1. Interestingly if the inset plot is the one with the additional outside call then it works? i.e. p2 + inset_element(p1, left = 0.6, bottom = 0.6, right = 1, top = 1) works as expected but p1 + inset_element(p2, left = 0.6, bottom = 0.6, right = 1, top = 1) throws the FUN(X[[i]], ...) : subscript out of bounds error

I am currently running ggplot2 v3.4.2 and patchwork v1.1.2

@thomasp85 thomasp85 added the bug an unexpected problem or unintended behavior label Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants