metrumresearchgroup / pmforest

Create forest plots
https://metrumresearchgroup.github.io/pmforest
Other
2 stars 0 forks source link

Pass latex2exp for axis titles #23

Open dpolhamus opened 1 year ago

dpolhamus commented 1 year ago

Would be nice to pass expressions or plotmath to x_lab, e.g., particularly latex2exp output.

barrettk commented 1 year ago

From offline conversation: The lines below should work. Specifically, I think we'll have to determine the class, and then correctly handle the plotmath attribute:

> lab.y <- latex2exp::TeX(paste("Probability of",str_replace(spec[[params$ep]]$short,"^Any","any")), output = "expression")
> lab.y
   LaTeX: Probability of any AE, Grade $\geq 3$ 
plotmath: 'Probability of any AE, Grade ' * {phantom() >= phantom()} * 3 
> sim_summary %>%
+   ungroup %>%
+   mutate(gl = sprintf("%s (%s)",JPGR, DOSCAT)) %>%
+   pmforest::summarize_data(value = prob, group = TYPEHER2, group_level= gl) %>%
+   pmforest::plot_forest(digits=2, x_lab = substitute(lab.y))
barrettk commented 1 year ago

Hey @dpolhamus, im just getting to this issue now.

I was able to get the following code to work with pmforest 0.1.0

Code

# Data
dataDir <- system.file("test-data", package = "pmforest")
plotData <- readRDS(file.path(dataDir, "plotData.RDS"))

# Summarize Data
sumData <- plotData %>%
  summarize_data(
    value = stat,
    group = GROUP,
    metagroup = param,
    group_level = LVL
  )

# latex2exp/plotmath label
lab.y <- latex2exp::TeX("probability of Grade $\\geq 3$", output = "expression")
> lab.y
   LaTeX: probability of Grade $\geq 3$ 
plotmath: 'probability of Grade ' * {phantom() >= phantom()} * 3 

Plot

plot_forest(sumData, x_lab = lab.y, CI_label=" ")

That yielded: image

As you can see, the label updated correctly. Note that substitute(lab.y) also worked, and returned the same plot. I'll leave the issue open for now just in case you discover some nuance in the near future.

Session Info

```r R version 4.1.1 (2021-08-10) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.5 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] pmforest_0.1.0 testthat_3.1.5 loaded via a namespace (and not attached): [1] pkgload_1.3.1 tidyr_1.2.1 here_1.0.1 pmtables_0.4.0 brio_1.1.3 shiny_1.7.3 assertthat_0.2.1 [8] renv_0.14.0 yaml_2.3.6 remotes_2.4.2 sessioninfo_1.2.2 pillar_1.8.1 glue_1.6.2 digest_0.6.30 [15] RColorBrewer_1.1-3 promises_1.2.0.1 colorspace_2.0-3 htmltools_0.5.3 httpuv_1.6.6 pkgconfig_2.0.3 devtools_2.4.5 [22] purrr_0.3.5 xtable_1.8-4 patchwork_1.1.2 scales_1.2.1 vdiffr_1.0.4 processx_3.8.0 later_1.3.0 [29] tzdb_0.3.0 tibble_3.1.8 farver_2.1.1 generics_0.1.3 ggplot2_3.4.0 usethis_2.1.6 ellipsis_0.3.2 [36] cachem_1.0.6 withr_2.5.0 cli_3.4.1 magrittr_2.0.3 crayon_1.5.2 mime_0.12 memoise_2.0.1 [43] evaluate_0.18 ps_1.7.2 fs_1.5.2 fansi_1.0.3 forcats_0.5.2 pkgbuild_1.3.1 profvis_0.3.7 [50] tools_4.1.1 prettyunits_1.1.1 hms_1.1.2 lifecycle_1.0.3 stringr_1.4.1 munsell_0.5.0 callr_3.7.3 [57] compiler_4.1.1 rlang_1.0.6 grid_4.1.1 rstudioapi_0.14 htmlwidgets_1.5.4 miniUI_0.1.1.1 labeling_0.4.2 [64] rmarkdown_2.18 gtable_0.3.1 DBI_1.1.3 R6_2.5.1 gridExtra_2.3 knitr_1.40 dplyr_1.0.10 [71] fastmap_1.1.0 utf8_1.2.2 yspec_0.5.1 rprojroot_2.0.3 latex2exp_0.9.5 readr_2.1.3 desc_1.4.2 [78] stringi_1.7.8 Rcpp_1.0.9 vctrs_0.5.0 tidyselect_1.2.0 xfun_0.34 urlchecker_1.0.1 ```