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 doesn't play nice with certain theme arguments #148

Closed
akarlinsky opened this issue Jan 23, 2020 · 5 comments
Closed

patchwork doesn't play nice with certain theme arguments #148

akarlinsky opened this issue Jan 23, 2020 · 5 comments

Comments

@akarlinsky
Copy link

akarlinsky commented Jan 23, 2020

If I change the spacing of the legend inside a theme, patchwork failes:

pacman::p_load(tidyverse, patchwork)

p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear, color=am))

theme_set(theme_classic())
p1 + p2

ggplottheme <- theme_classic() +
  theme(
    legend.box.spacing = margin(t=-5,b=-5),
  )
theme_set(ggplottheme)

p1 + p2
#> Error in grid.Call.graphics(C_setviewport, vp, TRUE): invalid 'layout.pos.col'

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

@geryan
Copy link

geryan commented Feb 13, 2020

Similar issue to above with legend position.

library(ggplot2)
library(patchwork)

p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp)) + 
  ggtitle('Plot 1')

p2 <- ggplot(mtcars) + 
  geom_bar(aes(x = gear, fill = factor(am))) + 
  facet_wrap(~cyl, nrow = 2) + 
  ggtitle('Plot 2')


# same as plot 2 but shifted legend
p3 <- ggplot(mtcars) + 
  geom_bar(aes(x = gear, fill = factor(am))) + 
  facet_wrap(~cyl, nrow = 2) + 
  ggtitle('Plot 3') +
  theme(legend.position = c(0.85, 0.2))


p1 + p2

p1 + p3
#> Error in FUN(X[[i]], ...): subscript out of bounds

Created on 2020-02-13 by the reprex package (v0.3.0)

@Sumidu
Copy link

Sumidu commented Oct 12, 2020

I've had a similar problem with the ggdark theme when trying to copy dimensions.

library(tidyverse)
library(patchwork)
library(ggdark)

plot_a <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp)) + 
  ggtitle('Plot 1') +
  dark_theme_minimal()

plot_b <- ggplot(mtcars) + 
  geom_bar(aes(x = gear, fill = factor(am))) + 
  facet_wrap(~cyl, nrow = 2) + 
  ggtitle('Plot 2') +
  dark_theme_minimal()

max_dims <- get_max_dim(plot_a, plot_b)
plot_a <- set_dim(plot_a, max_dims)
plot_b <- set_dim(plot_b, max_dims)
plot_a / plot_b

#> Error in grid.Call.graphics(C_setviewport, vp, TRUE) : illegal 'layout.pos.col'

@paocorrales
Copy link

I've updated {patchwork} to the most recent version and the same error arise when using the first example. I've also tried using the development version.

library(ggplot2)
#> Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'
#> when loading 'dplyr'
library(patchwork)


p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear, color=am))

theme_set(theme_classic())
p1 + p2

ggplottheme <- theme_classic() +
  theme(
    legend.box.spacing = margin(t=-5,b=-5),
  )
theme_set(ggplottheme)

p1 + p2
#> Error in grid.Call.graphics(C_setviewport, vp, TRUE): invalid 'layout.pos.col'

Created on 2021-01-19 by the reprex package (v0.3.0)

@thomasp85
Copy link
Owner

No - negative margins is not allowed

@paocorrales
Copy link

I should have changed the margins on the reprex. I'm trying with zero and positive margins and I have the same error.

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

5 participants