Skip to content

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

Closed

Description

@ltuijnder

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.

Activity

  1. ltuijnder commented on Aug 24, 2021

    @ltuijnder
    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.

  2. ltuijnder commented on Aug 31, 2021

    @ltuijnder
    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)

  3. 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)[/+] on Aug 31, 2021
  4. 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[/+] on Aug 31, 2021
  5. added
    bugan unexpected problem or unintended behavior
    on Aug 8, 2023
  6. added a commit that references this issue on May 31, 2024
    94f04c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions