gforge / forestplot

Advanced forest plots in R using grid graphics
44 stars 15 forks source link

Horizontal legend for grouped forest plot #59

Closed nkempkens closed 1 year ago

nkempkens commented 1 year ago

Hello, I encountered an error when trying to change the position of the legend for a grouped forest plot.

Minimal example:

library(forestplot)
data(dfHRQoL)

dfHRQoL |>
  dplyr::group_by(.data$group) |>
  forestplot::forestplot(
    legend_args = forestplot::fpLegend(
      pos = list("top", "align" = "horizontal")
    )
  )

results in Error in as.unit(e2) : object is not coercible to a unit. The plot is created, but without a legend.

If the align key is not used or set to "vertical", everything works fine. However, I would like the legend to be in one line for my graph. Any help would be much appreciated.

Best regards,

Niels

PS: Please find here the output of sessionInfo():

R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Zurich
tzcode source: internal

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

other attached packages:
[1] forestplot_3.1.2 abind_1.4-5      checkmate_2.2.0  devtools_2.4.5   usethis_2.2.2   

loaded via a namespace (and not attached):
 [1] gtable_0.3.3      xfun_0.39         ggplot2_3.4.2     htmlwidgets_1.6.2 remotes_2.4.2.1   processx_3.8.2   
 [7] callr_3.7.3       vctrs_0.6.3       tools_4.3.1       ps_1.7.5          generics_0.1.3    tibble_3.2.1     
[13] fansi_1.0.4       pkgconfig_2.0.3   data.table_1.14.8 lifecycle_1.0.3   compiler_4.3.1    stringr_1.5.0    
[19] tictoc_1.2        munsell_0.5.0     httpuv_1.6.11     htmltools_0.5.5   yaml_2.3.7        later_1.3.1      
[25] pillar_1.9.0      crayon_1.5.2      urlchecker_1.0.1  tidyr_1.3.0       ellipsis_0.3.2    cachem_1.0.8     
[31] sessioninfo_1.2.2 mime_0.12         tidyselect_1.2.0  digest_0.6.33     stringi_1.7.12    dplyr_1.1.2      
[37] purrr_1.0.1       fastmap_1.1.1     axcpt_0.0.1       colorspace_2.1-0  cli_3.6.1         magrittr_2.0.3   
[43] pkgbuild_1.4.2    utf8_1.2.3        withr_2.5.0       prettyunits_1.1.1 scales_1.2.1      promises_1.2.0.1 
[49] backports_1.4.1   rmarkdown_2.23    ggtext_0.1.2      progressr_0.13.0  memoise_2.0.1     shiny_1.7.4.1    
[55] evaluate_0.21     knitr_1.43        miniUI_0.1.1.1    profvis_0.3.8     rlang_1.1.1       gridtext_0.1.5   
[61] Rcpp_1.0.11       xtable_1.8-4      glue_1.6.2        xml2_1.3.5        pkgload_1.3.2.1   rstudioapi_0.15.0
[67] R6_2.5.1          fs_1.6.3
gforge commented 1 year ago

Fixed and on the way to CRAN