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

strip.placement = 'outside' #168

Closed
dleopold opened this issue Apr 23, 2020 · 3 comments
Closed

strip.placement = 'outside' #168

dleopold opened this issue Apr 23, 2020 · 3 comments

Comments

@dleopold
Copy link

There appears to be a problem rendering plots with facets when setting strip.placement='outside'. I see that the issue was referenced already #132. However, after updating to the github version of patchwork, there is still a problem but with a different error message:

library(ggplot2)
library(patchwork)
p <- ggplot(mpg, aes(displ, cty)) + 
  geom_point() +
  facet_grid(rows = vars(drv), switch='y') +
  theme(axis.title.y = element_blank(),
        strip.placement = 'outside')
p | p  

Error in FUN(X[[i]], ...) : subscript out of bounds
@tomlangbehn
Copy link

the issue seems to persist when facetting by rows and columns:

library(ggplot2)
library(patchwork)
p <- ggplot(mpg, aes(displ, cty)) + 
  geom_point() +
  facet_grid(rows = vars(drv), cols = vars(class), switch='y') +
  theme(axis.title.y = element_blank(),
        strip.placement = 'outside')
p | p 

Error in FUN(X[[i]], ...) : subscript out of bounds

@gregcox7
Copy link

Confirmed, this is still a problem when facetting by both rows and columns, but it looks like it occurs only when the facet labels are "switch"ed.

library(ggplot2)
library(patchwork)

# Works
p_rc_works <- ggplot(mpg, aes(displ, cty)) + 
    geom_point() +
    facet_grid(drv ~ class) +
    theme(strip.placement = 'outside')

print(p_rc_works + p_rc_works)

# Fails
p_rc_switch_y <- ggplot(mpg, aes(displ, cty)) + 
    geom_point() +
    facet_grid(drv ~ class, switch = "y") +
    theme(strip.placement = 'outside')

print(p_rc_switch_y + p_rc_switch_y)
# Error in FUN(X[[i]], ...) : subscript out of bounds

# Also fails
p_rc_switch_x <- ggplot(mpg, aes(displ, cty)) + 
    geom_point() +
    facet_grid(drv ~ class, switch = "x") +
    theme(strip.placement = 'outside')

print(p_rc_switch_x + p_rc_switch_x)
# Error in FUN(X[[i]], ...) : subscript out of bounds

@hummuscience
Copy link

I can confirm that this is still a problem as @gregcox7 mentions, it happens when axes are switched.

I understand that patchwork tries to align the plots usings X and Y axes. I am not sure what the best way is to solve this 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

4 participants