Skip to content

guides = 'collect' does not work with latest github version of ggplot2 #374

Open
@BenVolpe94

Description

@BenVolpe94

Hi! I'm currently using the latest github version of ggplot2 because it has a fix for an issue I encountered. I noticed however that this version broke the guides = 'collect' option in patchwork.

See example below:

# Load current main branch
devtools::dev_mode(on = T)
#> ✔ Dev mode: ON
library(ggplot2)
library(patchwork)

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

p2 <- ggplot(mtcars) + 
  geom_boxplot(aes(gear, disp, group = gear)) + 
  ggtitle('Plot 2')

p3 <- ggplot(mtcars) + 
  geom_point(aes(hp, wt, colour = mpg)) + 
  ggtitle('Plot 3')

p4 <- ggplot(mtcars) + 
  geom_bar(aes(gear)) + 
  facet_wrap(~cyl) + 
  ggtitle('Plot 4')

# Combine plots
p1 + p2 + p3 + p4 +
  plot_layout(guides = 'collect')
#> Error in identicalUnits(x): object is not a unit

# Session info
sessionInfo()
#> R version 4.3.3 (2024-02-29 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 11 x64 (build 22635)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=Dutch_Belgium.utf8  LC_CTYPE=Dutch_Belgium.utf8   
#> [3] LC_MONETARY=Dutch_Belgium.utf8 LC_NUMERIC=C                  
#> [5] LC_TIME=Dutch_Belgium.utf8    
#> 
#> time zone: Europe/Brussels
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] patchwork_1.2.0    ggplot2_3.5.1.9000
#> 
#> loaded via a namespace (and not attached):
#>  [1] utf8_1.2.4        generics_0.1.3    stringi_1.8.4     digest_0.6.36    
#>  [5] magrittr_2.0.3    evaluate_0.24.0   grid_4.3.3        pkgload_1.4.0    
#>  [9] fastmap_1.2.0     pkgbuild_1.4.4    sessioninfo_1.2.2 urlchecker_1.0.1 
#> [13] promises_1.3.0    purrr_1.0.2       fansi_1.0.6       scales_1.3.0     
#> [17] cli_3.6.3.9000    shiny_1.9.1       rlang_1.1.4       ellipsis_0.3.2   
#> [21] munsell_0.5.1     reprex_2.1.1      remotes_2.5.0     withr_3.0.1      
#> [25] cachem_1.1.0      yaml_2.3.10       devtools_2.4.5    tools_4.3.3      
#> [29] memoise_2.0.1     dplyr_1.1.4       colorspace_2.1-1  httpuv_1.6.15    
#> [33] vctrs_0.6.5       R6_2.5.1          mime_0.12         lifecycle_1.0.4  
#> [37] stringr_1.5.1     fs_1.6.4          htmlwidgets_1.6.4 usethis_3.0.0    
#> [41] miniUI_0.1.1.1    pkgconfig_2.0.3   pillar_1.9.0      later_1.3.2      
#> [45] gtable_0.3.5      glue_1.7.0        profvis_0.3.8     Rcpp_1.0.13      
#> [49] xfun_0.46         tibble_3.2.1      tidyselect_1.2.1  rstudioapi_0.16.0
#> [53] knitr_1.48        farver_2.1.2      xtable_1.8-4      htmltools_0.5.8.1
#> [57] labeling_0.4.3    rmarkdown_2.27    compiler_4.3.3

I get the following Traceback:

Error in identicalUnits(x) : object is not a unit
7. identicalUnits(x)
6. unit.c(legend.box.margin[4], widths, legend.box.margin[2])
5. guides_build(guides, theme)
4. assemble_guides(guide_grobs, theme)
3. build_patchwork(plot, plot$layout$guides %||% "auto")
2. print.patchwork(x)
1. (function (x, ...)
UseMethod("print"))(x)

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