Skip to content

Patchwork crashes when combining plots with empty facet rows and/or columns #273

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

Closed
ltuijnder opened this issue Aug 23, 2021 · 2 comments
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@ltuijnder
Copy link

Thanks for the amazing package! I really like it but I have encountered a bug the other day.
Below I give you a minimal example:


Combining figures that have an empty facet row results in a crash.

One can create a facet with an empty row using the ggforce::facet_wrap_paginate function. As shown in the minimal example below:

library(ggplot2)
library(ggforce)
library(patchwork)

out <- ggplot(diamonds) +
  geom_point(aes(carat, price), alpha = 0.1) +
  facet_wrap_paginate(~ cut:clarity, ncol = 3, nrow = 3, page = 5)

out # page 5 has an empty row

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

Created on 2021-08-23 by the reprex package (v2.0.1)

Package versions:
ggforce_0.3.3 patchwork_1.1.1 ggplot2_3.3.5


Other pages with fully or partially filled rows do not crash.

@ltuijnder
Copy link
Author

After playing around I encountered an even more minimal example just using patchwork and ggplot2:

library(patchwork)
library(ggplot2)

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

patch <- wrap_plots(p1, nrow = 2) # empty second row
patch + patch
#> Error in grid.Call.graphics(C_setviewport, vp, TRUE): invalid 'layout.pos.row'

Created on 2021-08-24 by the reprex package (v2.0.1)

Evidently, in this example I could have made better checks on the number of rows. Or if I want to go for a similar look I should use the patchwork::plot_spacer() function.

However, I do not have these luxuries when I use ggforce::facet_wrap_paginate and thus the problem persists.

@ltuijnder
Copy link
Author

It also crashes with empty columns in a very similar fashion:

library(patchwork)
library(ggplot2)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))

emptyCol <- wrap_plots(p1, ncol = 2)
emptyCol + emptyCol
#> Error in grid.Call.graphics(C_setviewport, vp, TRUE): invalid 'layout.pos.col'

Created on 2021-08-31 by the reprex package (v2.0.1)

@ltuijnder ltuijnder changed the title Patchwork crashes when combining plots with empty facet rows (ggforce) Patchwork crashes when combining plots with empty facet rows and/or columns (ggforce) Aug 31, 2021
@ltuijnder ltuijnder changed the title Patchwork crashes when combining plots with empty facet rows and/or columns (ggforce) Patchwork crashes when combining plots with empty facet rows and/or columns Aug 31, 2021
@thomasp85 thomasp85 added the bug an unexpected problem or unintended behavior label Aug 8, 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