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

print line plot #501

Closed mhallal1 closed 2 years ago

mhallal1 commented 2 years ago

UAT of safety app: https://rsconnect.roche.com/NEST/pre-release/safety/

Add result at the end of the code to chunks so that the plot gets printed. In the actual format below, a user needs to manually print the plot.


# 
# Automatically generated R code
# 
#   Running: /opt/rstudio-connect/mnt/app
#        on: rkaub00459.kau.roche.com
# R version: R version 4.0.3 (2020-10-10)
#      Date: Tue Jun  7 18:34:16 2022
# 
# Current libraries loaded (derived by .libPaths()):
#   - /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.0.3
#   - /opt/bee_tools/R/4.0.3/lib64/R/library
# 
# Packages versions: teal.modules.clinical (0.8.12.9018.1), tern (0.7.7.9020.1),
#                    rtables (0.5.1.2), formatters (0.3.1), teal.modules.general
#                    (0.2.13.9011.2), teal (0.11.0.9014.3), teal.transform
#                    (0.1.0.9013), teal.data (0.1.0.9007.4), shinyTree (0.2.7),
#                    magrittr (2.0.3), ggmosaic (0.3.3), ggplot2 (3.3.2),
#                    scda.2021 (0.1.3.9003.1), scda (0.1.3.9004.1), dplyr
#                    (1.0.9), shiny (1.5.0)

# Add any code to install/load your NEST environment here

library(shiny)
library(dplyr)
library(scda)
library(scda.2021)
library(ggplot2)
library(ggmosaic)
library(magrittr)
library(shinyTree)
library(teal.data)
library(teal.transform)
library(teal)
library(teal.modules.general)
library(formatters)
library(rtables)
library(tern)
library(teal.modules.clinical)

char_vars_adsl <- c("STUDYID", "USUBJID", "SUBJID", "SITEID", "INVID", "INVNAM")
ADSL <- synthetic_cdisc_data("latest")$adsl
ADLB <- synthetic_cdisc_data("latest")$adlb

# ADSL MD5 hash at the time of analysis: b02dedf9e00e0e8e66f4e5bc83c71a0d
# ADLB MD5 hash at the time of analysis: c9155e3c54b5354b89fc4d8ef8aa599a

ADSL_FILTERED <- ADSL
ADLB_FILTERED_ALONE <- ADLB
ADLB_FILTERED <- dplyr::inner_join(x = ADLB_FILTERED_ALONE, y = ADSL_FILTERED[, c("STUDYID", "USUBJID"), drop = FALSE], by = c("STUDYID", "USUBJID"))

ANL_1 <- ADLB_FILTERED %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL, AVALU)
ANL_2 <- ADSL_FILTERED %>% dplyr::select(STUDYID, USUBJID, ACTARM)
ANL_3 <- ADLB_FILTERED %>%
  dplyr::filter(PARAMCD == "ALT") %>%
  dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT)
ANL <- ANL_1
ANL <- dplyr::inner_join(ANL, ANL_2, by = c("STUDYID", "USUBJID"))
ANL <- dplyr::inner_join(ANL, ANL_3, by = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"))
ANL <- ANL %>% formatters::var_relabel(AVISIT = "Analysis Visit", AVAL = "Analysis Value", ACTARM = "Description of Actual Arm", PARAMCD = "Parameter Code", AVALU = "Analysis Value Unit")

anl <- ANL
variables <- control_lineplot_vars(x = "AVISIT", y = "AVAL", strata = "ACTARM", paramcd = "PARAMCD", y_unit = "AVALU")
grid::grid.newpage()
result <- g_lineplot(
  df = anl, variables = variables, interval = "mean_ci", mid = "mean", whiskers = c("mean_ci_lwr", "mean_ci_upr"), table = c("n", "mean_sd", "median", "range"), mid_type = "pl", mid_point_size = 2L, table_font_size = 4L, newpage = FALSE, title = "Plot of Mean and 95% Mean Confidence Interval of AVAL by Visit", subtitle = "", caption = "NEST PROJECT", y_lab = "AVAL Mean Values for", legend_title = NULL, ggtheme = ggplot2::theme_minimal(), control = control_summarize_vars(conf_level = 0.95),
  subtitle_add_paramcd = FALSE, subtitle_add_unit = FALSE
)
kpagacz commented 2 years ago

PR merged, closing