teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
534 stars 32 forks source link

Compatibility with ggtext::element_markdown() issue #161

Closed Timmo83 closed 2 weeks ago

Timmo83 commented 2 weeks ago

After re-installing packages on a new machine, when I go to run element_markdown() to format strip text on a facet_nested, facet_grid2 or facet_wrap2 object I get the following error:

Error in `FUN()`:
! Don't know how to get height of <integer> object

I think this has to do with the compatibility between ggh4x and ggtext, as the element_markdown() formatting of strip text still works on facet_wrap or facet_grid.

Examples below with facet_wrap(): works fine...

data("mtcars")

mtcar_names <- c("<span style='color:#C03830'>2</span>",
                 "<span style='color:#E7872B'>4</span>",
                 "<span style='color:#0080FF'>6</span>")
names(mtcar_names) <- c("4", "6", "8")

ggplot(mtcars, aes(x=vs, y=mpg))+
  geom_bar(position = "dodge", stat = "summary")+
  facet_wrap(cyl~., label = as_labeller(mtcar_names))+
  theme(strip.text = element_markdown())

image

Example below using facet_wrap2(): error.

ggplot(mtcars, aes(x=vs, y=mpg))+
  geom_bar(position = "dodge", stat = "summary")+
  facet_wrap2(cyl~., label = as_labeller(mtcar_names))+
  theme(strip.text = element_markdown())
Error in `FUN()`:
! Don't know how to get height of <integer> object
Run `rlang::last_trace()` to see where the error occurred.

I had this script working just fine prior to reinstallation, so I suspect it has to do with updates to ggtext (0.1.2), ggh4x (0.2.8) or ggplot2 (3.5.0). Any help appreciated - thanks in advance!

R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.utf8  LC_CTYPE=English_Australia.utf8    LC_MONETARY=English_Australia.utf8 LC_NUMERIC=C                       LC_TIME=English_Australia.utf8    

time zone: Australia/Sydney
tzcode source: internal

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

other attached packages:
 [1] ggtext_0.1.2       gridtext_0.1.5     scales_1.3.0       ggh4x_0.2.8        gridExtra_2.3      cowplot_1.1.3      ggthemes_5.1.0     RColorBrewer_1.1-3 paletteer_1.6.0   
[10] reader_1.0.6       NCmisc_1.2.0       data.table_1.15.2  ggeasy_0.1.4       rcompanion_2.4.36  rstatix_0.7.2      DHARMa_0.4.6       ggpubr_0.6.0       lubridate_1.9.3   
[19] forcats_1.0.0      stringr_1.5.1      purrr_1.0.2        readr_2.1.5        tidyr_1.3.1        tibble_3.2.1       tidyverse_2.0.0    dplyr_1.1.4        ggplot2_3.5.0     
[28] coin_1.4-3         survival_3.5-7     emmeans_1.10.0    

loaded via a namespace (and not attached):
 [1] gld_2.6.6           remotes_2.5.0       rematch2_2.1.2      sandwich_3.1-0      readxl_1.4.3        rlang_1.1.3         magrittr_2.0.3      multcomp_1.4-25    
 [9] matrixStats_1.2.0   e1071_1.7-14        compiler_4.3.2      callr_3.7.5         vctrs_0.6.5         pkgconfig_2.0.3     crayon_1.5.2        backports_1.4.1    
[17] labeling_0.4.3      utf8_1.2.4          markdown_1.13       tzdb_0.4.0          ps_1.7.6            nloptr_2.0.3        xfun_0.42           modeltools_0.2-23  
[25] broom_1.0.5         parallel_4.3.2      DescTools_0.99.54   R6_2.5.1            stringi_1.8.3       car_3.1-2           boot_1.3-28.1       lmtest_0.9-40      
[33] cellranger_1.1.0    estimability_1.5    Rcpp_1.0.12         zoo_1.8-12          Matrix_1.6-1.1      splines_4.3.2       timechange_0.3.0    tidyselect_1.2.1   
[41] rstudioapi_0.15.0   abind_1.4-5         codetools_0.2-19    processx_3.8.4      curl_5.2.1          pkgbuild_1.4.4      lattice_0.21-9      plyr_1.8.9         
[49] withr_3.0.0         coda_0.19-4.1       desc_1.4.3          proxy_0.4-27        xml2_1.3.6          pillar_1.9.0        carData_3.0-5       nortest_1.0-4      
[57] stats4_4.3.2        generics_0.1.3      hms_1.1.3           commonmark_1.9.1    munsell_0.5.1       rootSolve_1.8.2.4   minqa_1.2.6         xtable_1.8-4       
[65] class_7.3-22        glue_1.7.0          lmom_3.0            tools_4.3.2         lme4_1.1-35.1       ggsignif_0.6.4      Exact_3.2           mvtnorm_1.2-4      
[73] grid_4.3.2          libcoin_1.0-10      colorspace_2.1-0    nlme_3.1-163        patchwork_1.2.0     cli_3.6.2           fansi_1.0.6         expm_0.999-9       
[81] gtable_0.3.5        TH.data_1.1-2       farver_2.1.1        lifecycle_1.0.4     httr_1.4.7          multcompView_0.1-10 MASS_7.3-60
teunbrand commented 2 weeks ago

Thanks for the report! I expect this to be the same as #151, #153 and #156. You can install from GitHub to solve the issue: devtools::install_github("teunbrand/ggh4x").

Timmo83 commented 2 weeks ago

Thanks so much for the rapid answer!