Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g_forest() clipping the output #73

Closed
cicdguy opened this issue Aug 10, 2021 · 3 comments
Closed

g_forest() clipping the output #73

cicdguy opened this issue Aug 10, 2021 · 3 comments

Comments

@cicdguy
Copy link
Contributor

cicdguy commented Aug 10, 2021

Original message

Reporting an Issue with tern

g_forest() output is clipped when width is not large enough, when used within an RStudio session while developing code this is uncomfortable. I tried increasing par() argument without success.

Even when saving the plot in a PDF file with pdf() you need multiple trial and errors to get the width large enough for the plot to show correctly.

Is there a way to make g_forest() behave like a "normal" plot?

Here's a MRE, is simply what is in the help file of g_forest()

library(random.cdisc.data)
library(dplyr)

ADSL <- radsl(seed = 1)
ADTTE <- radtte(ADSL, seed = 2)

ADTTE_f <- ADTTE %>% 
  filter(PARAMCD == "OS" & ARMCD %in% c("ARM B", "ARM A")) %>%
  mutate(ARMCD = droplevels(ARMCD))

tbl <- t_forest_tte(
  tte = ADTTE_f$AVAL,
  is_event = ADTTE_f$CNSR == 0,
  col_by = ADTTE_f$ARMCD, 
  group_data = droplevels(ADTTE_f[, c("SEX", "RACE")]), # note factors required
  ties = "exact",
  dense_header = TRUE
)

# note plot requires a certain width
g_forest(
  tbl = tbl,
  col_x = 8,
  col_ci = 9,
  vline = 1,
  forest_header = c("Treatement\nBetter", "Comparison\nBetter"),
  xlim = c(.1, 10),
  logx = TRUE,
  x_at = c(.1, 1, 10)
)

## save graph on file
pdf(file = "test-g_forest.pdf", width = 10, height = 8)
g_forest(
  tbl = tbl,
  col_x = 8,
  col_ci = 9,
  vline = 1,
  forest_header = c("Treatement\nBetter", "Comparison\nBetter"),
  xlim = c(.1, 10),
  logx = TRUE,
  x_at = c(.1, 1, 10)
)
dev.off()

> utils::sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblas-r0.2.20.so

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] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] teal.modules.clinical_0.6.0 teal.utils_0.0.1            random.cdisc.data_0.2.0    
 [4] tern_0.6.1                  rtables_0.1.1               teal_0.6.0                 
 [7] shiny_1.3.1                 kableExtra_1.1.0            data.table_1.12.2          
[10] magrittr_1.5                forcats_0.4.0               stringr_1.4.0              
[13] dplyr_0.8.0.1               purrr_0.3.2                 readr_1.3.1                
[16] tidyr_0.8.3                 tibble_2.1.1                tidyverse_1.2.1            
[19] rocheBCE_2.4                readxl_1.3.1                rms_5.1-3                  
[22] SparseM_1.77                Hmisc_4.2-0                 ggplot2_3.1.1              
[25] Formula_1.2-3               lattice_0.20-38             glmnet_2.0-16              
[28] foreach_1.4.4               Matrix_1.2-17               survival_2.44-1.1          
[31] DescTools_0.99.28           knitr_1.22                  ROCR_1.0-7                 
[34] gplots_3.0.1.1             

loaded via a namespace (and not attached):
 [1] nlme_3.1-139        bitops_1.0-6        lubridate_1.7.4     webshot_0.5.1      
 [5] RColorBrewer_1.1-2  httr_1.4.0          tools_3.5.3         backports_1.1.4    
 [9] R6_2.4.0            rpart_4.1-15        KernSmooth_2.23-15  lazyeval_0.2.2     
[13] colorspace_1.4-1    nnet_7.3-12         withr_2.1.2         tidyselect_0.2.5   
[17] gridExtra_2.3       compiler_3.5.3      cli_1.1.0           rvest_0.3.3        
[21] quantreg_5.38       htmlTable_1.13.1    expm_0.999-4        xml2_1.2.0         
[25] sandwich_2.5-1      caTools_1.17.1.2    scales_1.0.0        checkmate_1.9.1    
[29] polspline_1.1.14    mvtnorm_1.0-10      digest_0.6.18       foreign_0.8-71     
[33] rmarkdown_1.12      base64enc_0.1-3     pkgconfig_2.0.2     htmltools_0.3.6    
[37] manipulate_1.0.1    htmlwidgets_1.3     rlang_0.3.4         rstudioapi_0.10    
[41] generics_0.0.2      zoo_1.8-5           jsonlite_1.6        gtools_3.8.1       
[45] acepack_1.4.1       Rcpp_1.0.1          munsell_0.5.0       yaml_2.2.0         
[49] stringi_1.4.3       multcomp_1.4-10     MASS_7.3-51.3       plyr_1.8.4         
[53] gdata_2.18.0        promises_1.0.1      crayon_1.3.4        haven_2.1.0        
[57] splines_3.5.3       hms_0.4.2           pillar_1.3.1        boot_1.3-20        
[61] codetools_0.2-16    glue_1.3.1          packrat_0.5.0       evaluate_0.13      
[65] latticeExtra_0.6-28 modelr_0.1.4        httpuv_1.5.1        MatrixModels_0.4-1 
[69] cellranger_1.1.0    gtable_0.3.0        assertthat_0.2.1    xfun_0.5           
[73] mime_0.6            xtable_1.8-3        broom_0.5.2         later_0.8.0        
[77] viridisLite_0.3.0   iterators_1.0.10    cluster_2.0.8       TH.data_1.0-10    ```


Provenance: 

Creator: mattielf


## Still error

```R
library(scda)
library(tern)
library(dplyr)

adtte <- synthetic_cdisc_data("latest")$adtte

# Save variable labels before data processing steps.
adtte_labels <- formatters::var_labels(adtte)

adtte_f <- adtte %>%
  filter(
    PARAMCD == "OS",
    ARM %in% c("B: Placebo", "A: Drug X"),
    SEX %in% c("M", "F")
  ) %>%
  mutate(
    # Reorder levels of ARM to display reference arm before treatment arm.
    ARM = droplevels(forcats::fct_relevel(ARM, "B: Placebo")),
    SEX = droplevels(SEX),
    AVALU = as.character(AVALU),
    is_event = CNSR == 0
  )


df <- extract_survival_subgroups(
  variables = list(
    tte = "AVAL",
    is_event = "is_event",
    arm = "ARM", subgroups = c("SEX", "BMRKR2")
  ),
  data = adtte_f
)

table_hr <- basic_table() %>%
  tabulate_survival_subgroups(df, time_unit = adtte_f$AVALU[1])

g_forest(table_hr)

Expect

image

Only get the following

image

@cicdguy
Copy link
Contributor Author

cicdguy commented Aug 10, 2021

I have made a minimum width for the table columns, hence only the "forest" part is resizing. The minimal column width might be a bit conservative, I will have a look at it.

Provenance:

Creator: waddella

@shajoezhu
Copy link
Contributor

we should close this with insightsengineering/teal.modules.clinical#911 now

@edelarua
Copy link
Contributor

edelarua commented Jan 2, 2024

Closed by #1158

@edelarua edelarua closed this as completed Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants