-
Notifications
You must be signed in to change notification settings - Fork 163
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
Comments
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) |
I've had a similar problem with the 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' |
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) |
No - negative margins is not allowed |
I should have changed the margins on the reprex. I'm trying with zero and positive margins and I have the same error. |
If I change the spacing of the legend inside a theme, patchwork failes:
Created on 2020-01-23 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: