insightsengineering / teal.modules.clinical

Provides teal modules for the standard clinical trials outputs
https://insightsengineering.github.io/teal.modules.clinical/
Other
32 stars 17 forks source link

[Bug]: Ggplot2_args theme not working #792

Open guj54 opened 1 year ago

guj54 commented 1 year ago

What happened?

It seems that the parameter “theme” doesn’t work. For example, when I have a lineplot and I want the caption to be at the left side, I use the following code: tm_g_lineplot( ... ggplot2_args=teal.widgets::ggplot2_args( labs = list(caption = "caption"), theme = list(plot.caption = element_text(hjust = 0)) ) ) but it seems the theme is ignored, since the caption still appears on the right side (default), and when I click on “show R code”, the caption is there but plot.caption is missing.

sessionInfo()

No response

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

thomas-neitmann commented 1 year ago

I have observed the same with both tm_g_ipp() and tm_g_lineplot() so I assume this is a global issue. Here's a reproducible example that shows changing the plot theme does not work.

library(teal.modules.clinical)
library(ggplot2)
library(nestcolor)

adsl <- tmc_ex_adsl %>% dplyr::slice(1:20)
adlb <- tmc_ex_adlb %>% dplyr::filter(USUBJID %in% adsl$USUBJID)

adsl <- df_explicit_na(adsl)
adlb <- df_explicit_na(adlb) %>% dplyr::filter(AVISIT != "SCREENING")

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", adsl),
    cdisc_dataset("ADLB", adlb)
  ),
  modules = modules(
    tm_g_ipp(
      label = "Individual Patient Plot",
      dataname = "ADLB",
      arm_var = choices_selected(
        value_choices(adlb, "ARMCD"),
        "ARM A"
      ),
      paramcd = choices_selected(
        value_choices(adlb, "PARAMCD"),
        "ALT"
      ),
      aval_var = choices_selected(
        variable_choices(adlb, c("AVAL", "CHG")),
        "AVAL"
      ),
      avalu_var = choices_selected(
        variable_choices(adlb, c("AVALU")),
        "AVALU",
        fixed = TRUE
      ),
      id_var = choices_selected(
        variable_choices(adlb, c("USUBJID")),
        "USUBJID",
        fixed = TRUE
      ),
      visit_var = choices_selected(
        variable_choices(adlb, c("AVISIT")),
        "AVISIT"
      ),
      base_var = choices_selected(
        variable_choices(adlb, c("BASE")),
        "BASE",
        fixed = TRUE
      ),
      add_baseline_hline = FALSE,
      separate_by_obs = FALSE,
      ggplot2_args = teal.widgets::ggplot2_args(
        theme = list(legend.position = "top", text = element_text(size = 20))
      )
    )
  )
)
if (interactive()) {
  shinyApp(ui = app$ui, server = app$server)
}

Session Info

R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] ggplot2_3.4.2                nestcolor_0.1.2             
 [3] teal.modules.clinical_0.8.15 tern_0.8.5                  
 [5] rtables_0.6.2                formatters_0.5.1            
 [7] teal_0.13.0                  teal.transform_0.3.0        
 [9] magrittr_2.0.3               teal.data_0.2.0             
[11] shiny_1.7.4.1               

loaded via a namespace (and not attached):
 [1] sass_0.4.7          tidyr_1.3.0         jsonlite_1.8.7      splines_4.2.0      
 [5] R.utils_2.12.2      bslib_0.5.0         teal.slice_0.3.0    Rdpack_2.4         
 [9] assertthat_0.2.1    teal.code_0.3.0     tern.gee_0.1.0      yaml_2.3.7         
[13] pillar_1.9.0        backports_1.4.1     lattice_0.20-45     glue_1.6.2         
[17] teal.widgets_0.3.0  digest_0.6.33       promises_1.2.0.1    rbibutils_2.2.13   
[21] checkmate_2.2.0     colorspace_2.1-0    R.oo_1.25.0         htmltools_0.5.5    
[25] httpuv_1.6.11       Matrix_1.6-0        pkgconfig_2.0.3     broom_1.0.5        
[29] logger_0.2.2        purrr_1.0.1         xtable_1.8-4        mvtnorm_1.2-2      
[33] scales_1.2.1        fontawesome_0.5.1   later_1.3.1         emmeans_1.8.7      
[37] tibble_3.2.1        styler_1.10.1       farver_2.1.1        generics_0.1.3     
[41] ellipsis_0.3.2      cachem_1.0.8        withr_2.5.0         shinyjs_2.1.0      
[45] shinyvalidate_0.1.2 geepack_1.3.9       cli_3.6.1           survival_3.3-1     
[49] mime_0.12           memoise_2.0.1       estimability_1.4.1  evaluate_0.21      
[53] R.methodsS3_1.8.2   fansi_1.0.4         R.cache_0.16.0      nlme_3.1-157       
[57] MASS_7.3-56         forcats_1.0.0       teal.reporter_0.1.1 tools_4.2.0        
[61] lifecycle_1.0.3     munsell_0.5.0       compiler_4.2.0      jquerylib_0.1.4    
[65] rlang_1.1.1         grid_4.2.0          rstudioapi_0.15.0   labeling_0.4.2     
[69] rmarkdown_2.23      shinyWidgets_0.7.6  gtable_0.3.3        teal.logger_0.1.1  
[73] R6_2.5.1            knitr_1.43          dplyr_1.1.2         fastmap_1.1.1      
[77] utf8_1.2.3          Rcpp_1.0.11         vctrs_0.6.3         tidyselect_1.2.0   
[81] xfun_0.39