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 faceted plot has manually-placed legend #144

Closed
patrickbarks opened this issue Jan 6, 2020 · 1 comment
Closed

Error when faceted plot has manually-placed legend #144

patrickbarks opened this issue Jan 6, 2020 · 1 comment

Comments

@patrickbarks
Copy link

I'm getting an error when I try to use patchwork on a faceted ggplot with a manually-placed legend (i.e. theme(legend.position = ...)). Here's a reprex.

library(ggplot2)
library(patchwork)

p1 <- ggplot(mtcars, aes(mpg, disp, col = as.factor(gear))) +
  geom_point() +
  facet_wrap(~ cyl) +
  theme(legend.position = c(0.1, 0.7))

# plot by itself
p1

# plot within patchwork
p1 / p1
#> Error in FUN(X[[i]], ...): subscript out of bounds
wrap_plots(p1, p1)
#> Error in FUN(X[[i]], ...): subscript out of bounds

Created on 2020-01-06 by the reprex package (v0.3.0)

It works fine when I remove the facet_wrap(), or the theme(legend.position = ...) line. Something about both of them together seems to cause an issue.

brodieG added a commit to brodieG/patchwork that referenced this issue Jan 8, 2020
I figured out how to get the collected guide on
the bottom of the plot by finding issue thomasp85#144.  It
might be worth it to add more explicit docs in the
package proper.

Also, bonus typo fix.  Documents on the whole are
excellent, really a pleasure to read through them
@avigotsky
Copy link

I am having the same issue. Any help or workarounds would be greatly appreciated!

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