ggforce icon indicating copy to clipboard operation
ggforce copied to clipboard

facet_wrap_paginate fails when last page contains only one panel

Open burlab opened this issue 5 years ago • 5 comments

Hi Thomas,

facet_wrap_paginate seems to fail now with faceted plots when the last page contains only one panel:

ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~ cut:clarity, ncol = 3, nrow = 1, page = 14)
>#Error: Cannot create zero-length unit vector ("unit" subsetting)

However, when only one panel per page is plotted then all works perfectly:

ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~ cut:clarity, ncol = 1, nrow = 1, page = 40)

session_info()

Session info --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 4.0.0 (2020-04-24)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_Singapore.1252      
 ctype    English_Singapore.1252      
 tz       Asia/Kuala_Lumpur           
 date     2020-05-09                  

- Packages ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package        * version    date       lib source                            
 assertthat       0.2.1      2019-03-21 [1] CRAN (R 4.0.0)                    
 cli              2.0.2      2020-02-28 [1] CRAN (R 4.0.0)                    
 clipr            0.7.0      2019-07-23 [1] CRAN (R 4.0.0)                    
 colorspace       1.4-1      2019-03-18 [1] CRAN (R 4.0.0)                    
 crayon           1.3.4      2017-09-16 [1] CRAN (R 4.0.0)                    
 digest           0.6.25     2020-02-23 [1] CRAN (R 4.0.0)                    
 dplyr            0.8.5      2020-03-07 [1] CRAN (R 4.0.0)                    
 ellipsis         0.3.0      2019-09-20 [1] CRAN (R 4.0.0)                    
 evaluate         0.14       2019-05-28 [1] CRAN (R 4.0.0)                    
 fansi            0.4.1      2020-01-08 [1] CRAN (R 4.0.0)                    
 farver           2.0.3      2020-01-16 [1] CRAN (R 4.0.0)                    
 formatR          1.7        2019-06-11 [1] CRAN (R 4.0.0)                    
 futile.logger    1.4.3      2016-07-10 [1] CRAN (R 4.0.0)                    
 futile.options   1.0.1      2018-04-20 [1] CRAN (R 4.0.0)                    
 ggforce        * 0.3.1.9000 2020-05-07 [1] Github (thomasp85/ggforce@b21e445)
 ggplot2        * 3.3.0.9000 2020-05-07 [1] Github (tidyverse/ggplot2@1d4c573)
 ggsignif         0.6.0      2019-08-08 [1] CRAN (R 4.0.0)                    
 glue             1.4.0      2020-04-03 [1] CRAN (R 4.0.0)                    
 gtable           0.3.0      2019-03-25 [1] CRAN (R 4.0.0)                    
 htmltools        0.4.0      2019-10-04 [1] CRAN (R 4.0.0)                    
 knitr            1.28       2020-02-06 [1] CRAN (R 4.0.0)                    
 labeling         0.3        2014-08-23 [1] CRAN (R 4.0.0)                    
 lambda.r         1.2.4      2019-09-18 [1] CRAN (R 4.0.0)                    
 lifecycle        0.2.0      2020-03-06 [1] CRAN (R 4.0.0)                    
 magrittr         1.5        2014-11-22 [1] CRAN (R 4.0.0)                    
 MASS             7.3-51.5   2019-12-20 [2] CRAN (R 4.0.0)                    
 munsell          0.5.0      2018-06-12 [1] CRAN (R 4.0.0)                    
 pillar           1.4.4      2020-05-05 [1] CRAN (R 4.0.0)                    
 pkgconfig        2.0.3      2019-09-22 [1] CRAN (R 4.0.0)                    
 polyclip         1.10-0     2019-03-14 [1] CRAN (R 4.0.0)                    
 purrr            0.3.4      2020-04-17 [1] CRAN (R 4.0.0)                    
 R6               2.4.1      2019-11-12 [1] CRAN (R 4.0.0)                    
 Rcpp             1.0.4.6    2020-04-09 [1] CRAN (R 4.0.0)                    
 rlang            0.4.6      2020-05-02 [1] CRAN (R 4.0.0)                    
 rmarkdown        2.1        2020-01-20 [1] CRAN (R 4.0.0)                    
 rstudioapi       0.11       2020-02-07 [1] CRAN (R 4.0.0)                    
 scales           1.1.0      2019-11-18 [1] CRAN (R 4.0.0)                    
 sessioninfo      1.1.1      2018-11-05 [1] CRAN (R 4.0.0)                    
 tibble           3.0.1      2020-04-20 [1] CRAN (R 4.0.0)                    
 tidyselect       1.0.0      2020-01-27 [1] CRAN (R 4.0.0)                    
 tweenr           1.0.1      2018-12-14 [1] CRAN (R 4.0.0)                    
 vctrs            0.2.4      2020-03-10 [1] CRAN (R 4.0.0)                    
 withr            2.2.0      2020-04-20 [1] CRAN (R 4.0.0)                    
 xfun             0.13       2020-04-13 [1] CRAN (R 4.0.0)                    
 yaml             2.2.1      2020-02-01 [1] CRAN (R 4.0.0)                    

[1] C:/Users/bobur/Documents/R/win-library/4.0
[2] C:/Program Files/R/R-4.0.0/library

burlab avatar May 08 '20 16:05 burlab

Error is not limited to when one panel is on the last page, example below should have two on a page for three.

library(ggforce)
graphdata <- data.frame(y=rnorm(200),x=rnorm(200),facetMaker=sample(c("A","B","C","D","E"),size=200,replace = TRUE))
ggplot(data=graphdata,aes(x=x)) + geom_line(aes(y=y))+
facet_wrap_paginate(~facetMaker,ncol=3,nrow=1,page=2)
>Fehler: Cannot create zero-length unit vector ("unit" subsetting)

If transposing the plot area the output is correct with 2 graphs on the last page

library(ggforce)
graphdata <- data.frame(y=rnorm(200),x=rnorm(200),facetMaker=sample(c("A","B","C","D","E"),size=200,replace = TRUE))
ggplot(data=graphdata,aes(x=x)) + geom_line(aes(y=y))+
facet_wrap_paginate(~facetMaker,ncol=1, nrow=3, page=2)

njc-econ avatar Jun 30 '20 16:06 njc-econ

I rise this topic as well. I have noticed that when I have 1 or 2 plots on the last page (3 cols x 2 rows layout), it fails (IDE : R studio running on R 4.0). Interestingly, it works fine in Visual Studio 2017 and R studio running on R version 3.5.3. So it is most probably incompatibility of the package with new R version 4.0.2.

sessionInfo() for R studio running on R 4.0 version 4.0.2 (2020-06-22) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] goseq_1.40.0 geneLenDataBase_1.24.0 BiasedUrn_1.07
[4] stringr_1.4.0 stringi_1.4.6 limma_3.44.3
[7] sva_3.36.0 BiocParallel_1.22.0 genefilter_1.70.0
[10] mgcv_1.8-31 nlme_3.1-148 ggforce_0.3.1
[13] tibble_3.0.1 tidyr_1.1.0 dplyr_1.0.0
[16] ggplot2_3.3.2 tm_0.7-7 NLP_0.2-0

loaded via a namespace (and not attached): [1] colorspace_1.4-1 ellipsis_0.3.1 htmlTable_2.0.1
[4] XVector_0.28.0 GenomicRanges_1.40.0 base64enc_0.1-3
[7] rstudioapi_0.11 farver_2.0.3 bit64_0.9-7
[10] AnnotationDbi_1.50.1 xml2_1.3.2 splines_4.0.2
[13] knitr_1.29 polyclip_1.10-0 Formula_1.2-3
[16] Rsamtools_2.4.0 annotate_1.66.0 cluster_2.1.0
[19] GO.db_3.11.4 dbplyr_1.4.4 png_0.1-7
[22] BiocManager_1.30.10 compiler_4.0.2 httr_1.4.1
[25] backports_1.1.7 assertthat_0.2.1 Matrix_1.2-18
[28] tweenr_1.0.1 htmltools_0.5.0 acepack_1.4.1
[31] prettyunits_1.1.1 tools_4.0.2 gtable_0.3.0
[34] glue_1.4.1 GenomeInfoDbData_1.2.3 rappdirs_0.3.1
[37] tinytex_0.24 Rcpp_1.0.4.6 slam_0.1-47
[40] Biobase_2.48.0 vctrs_0.3.1 Biostrings_2.56.0
[43] rtracklayer_1.48.0 xfun_0.15 lifecycle_0.2.0
[46] XML_3.99-0.4 edgeR_3.30.3 zlibbioc_1.34.0
[49] MASS_7.3-51.6 scales_1.1.1 hms_0.5.3
[52] parallel_4.0.2 SummarizedExperiment_1.18.1 RColorBrewer_1.1-2
[55] curl_4.3 memoise_1.1.0 gridExtra_2.3
[58] biomaRt_2.44.1 rpart_4.1-15 latticeExtra_0.6-29
[61] RSQLite_2.2.0 S4Vectors_0.26.1 checkmate_2.0.0
[64] GenomicFeatures_1.40.0 BiocGenerics_0.34.0 GenomeInfoDb_1.24.2
[67] rlang_0.4.6 pkgconfig_2.0.3 matrixStats_0.56.0
[70] bitops_1.0-6 lattice_0.20-41 purrr_0.3.4
[73] labeling_0.3 GenomicAlignments_1.24.0 htmlwidgets_1.5.1
[76] bit_1.1-15.2 tidyselect_1.1.0 magrittr_1.5
[79] R6_2.4.1 IRanges_2.22.2 generics_0.0.2
[82] Hmisc_4.4-0 DelayedArray_0.14.0 DBI_1.1.0
[85] pillar_1.4.4 foreign_0.8-80 withr_2.2.0
[88] survival_3.1-12 RCurl_1.98-1.2 nnet_7.3-14
[91] crayon_1.3.4 BiocFileCache_1.12.0 jpeg_0.1-8.1
[94] progress_1.2.2 locfit_1.5-9.4 grid_4.0.2
[97] data.table_1.12.8 blob_1.2.1 digest_0.6.25
[100] xtable_1.8-4 openssl_1.4.1 stats4_4.0.2
[103] munsell_0.5.0 askpass_1.1

sessionInfo() for VS2017 running on R version 3.5.3 R version 3.5.3 (2019-03-11) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] BiasedUrn_1.07 stringr_1.4.0 stringi_1.4.6 limma_3.38.3 ggforce_0.3.1 tibble_3.0.1 tidyr_1.0.2
[8] dplyr_0.8.5 ggplot2_3.3.2 tm_0.7-7 NLP_0.2-0

loaded via a namespace (and not attached): [1] tidyselect_1.0.0 slam_0.1-47 purrr_0.3.4 splines_3.5.3 lattice_0.20-38 colorspace_1.4-1 [7] rtvs_1.0.0.0 vctrs_0.2.4 base64enc_0.1-3 survival_3.1-12 rlang_0.4.5 pillar_1.4.4
[13] glue_1.4.0 withr_2.2.0 tweenr_1.0.1 lifecycle_0.2.0 munsell_0.5.0 gtable_0.3.0
[19] labeling_0.3 parallel_3.5.3 Rcpp_1.0.4.6 acepack_1.4.1 scales_1.1.1 farver_2.0.3
[25] digest_0.6.25 polyclip_1.10-0 grid_3.5.3 tools_3.5.3 magrittr_1.5 Formula_1.2-3
[31] crayon_1.3.4 pkgconfig_2.0.3 MASS_7.3-51.1 ellipsis_0.3.0 Matrix_1.2-15 xml2_1.3.2
[37] assertthat_0.2.1 R6_2.4.1 compiler_3.5.3

sessionInfo() for R studio running on R 3.5.3 R version 3.5.3 (2019-03-11) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] mgcv_1.8-27 nlme_3.1-137 BiasedUrn_1.07 stringr_1.4.0 stringi_1.4.6 [6] limma_3.38.3 ggforce_0.3.1 tibble_3.0.1 tidyr_1.0.2 dplyr_0.8.5
[11] ggplot2_3.3.2 tm_0.7-7 NLP_0.2-0

loaded via a namespace (and not attached): [1] tinytex_0.24 tidyselect_1.0.0 xfun_0.13 slam_0.1-47
[5] purrr_0.3.4 splines_3.5.3 lattice_0.20-38 colorspace_1.4-1
[9] vctrs_0.2.4 stats4_3.5.3 base64enc_0.1-3 survival_3.1-12
[13] rlang_0.4.5 pillar_1.4.4 glue_1.4.0 withr_2.2.0
[17] tweenr_1.0.1 BiocGenerics_0.28.0 lifecycle_0.2.0 munsell_0.5.0
[21] gtable_0.3.0 Biobase_2.42.0 labeling_0.3 parallel_3.5.3
[25] Rcpp_1.0.4.6 xtable_1.8-4 acepack_1.4.1 scales_1.1.1
[29] BiocManager_1.30.10 S4Vectors_0.20.1 farver_2.0.3 digest_0.6.25
[33] polyclip_1.10-0 grid_3.5.3 bitops_1.0-6 tools_3.5.3
[37] magrittr_1.5 RCurl_1.98-1.2 Formula_1.2-3 crayon_1.3.4
[41] pkgconfig_2.0.3 MASS_7.3-51.1 ellipsis_0.3.0 Matrix_1.2-15
[45] xml2_1.3.2 assertthat_0.2.1 rstudioapi_0.11 R6_2.4.1
[49] compiler_3.5.3

Agpa88 avatar Jul 09 '20 11:07 Agpa88

As a side note, the same problem occurs when using the newest version of ggforce (v0.3.2) with R version 4.0.2

Agpa88 avatar Jul 09 '20 11:07 Agpa88

The fix proposed in https://github.com/thomasp85/ggforce/pull/238 resolved this issue for me, thanks @crotoc!

I applied the fix to ggforce at the last available commit 1f17eb3cdb0ef54a6ed5dcb77ef5fecb195c90e4 from Feb 22, 2021 using R version 4.1.2 (2021-11-01)

dschlaep avatar Dec 14 '21 21:12 dschlaep

This issue is still open. Can you please include the solution from crotoc? When I install the master branch from crotoc the issue is solved (ggforce * 0.3.2.9000 2022-05-06 [1] Github (https://github.com/crotoc/ggforce/commit/599d50e)) as dschlaep also did. However, when I update from thomasp85 (version 0.3.3) the solution from crotoc disappears. I am using R version 4.2.0 (2022-04-22).

mrbladergroen avatar May 19 '22 14:05 mrbladergroen