Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate density ranges based on
treatment
name and based on AVICI…
…TCD for density plot (#308) Fixes insightsengineering/goshawk#192 For proper density calculations, you need to calculate ranges within groups inside the plot. Groups are created based on treatment variable and based on AVICITCD plot. So the max ranges need to be calculated in each group, and the max needs to be extracted. > Set filters to: ADSL -> SEX -> Male, ADSL -> AGE -> 31.41, 35 # How it looked before <img width="665" alt="image" src="https://github.com/user-attachments/assets/344d408e-5357-4ebc-b037-7fa483b0e052"> # How it looks now <img width="664" alt="image" src="https://github.com/user-attachments/assets/d84fd7b1-6a06-43f9-8ff4-97310dcc629a"> # Example code <details><summary> Example from `?tm_g_gh_density_distribution_plot` </summary> ```r pkgload::load_all("../teal.widgets") pkgload::load_all("../teal") pkgload::load_all(".") data <- teal_data() data <- within(data, { library(dplyr) library(stringr) # original ARM value = dose value arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) ADSL <- rADSL ADLB <- rADLB var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate( AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste("W", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")), TRUE ~ as.character(NA) ), AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)), TRUE ~ as.numeric(NA) ), AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN), TRTORD = case_when( ARMCD == "ARM C" ~ 1, ARMCD == "ARM B" ~ 2, ARMCD == "ARM A" ~ 3 ), ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]), ARM = factor(ARM) %>% reorder(TRTORD), ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]), ACTARM = factor(ACTARM) %>% reorder(TRTORD) ) attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]] }) datanames <- c("ADSL", "ADLB") datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] app <- init( data = data, modules = modules( tm_g_gh_density_distribution_plot( label = "Density Distribution Plot", dataname = "ADLB", param_var = "PARAMCD", param = choices_selected(c("ALT", "CRP", "IGA"), "ALT"), xaxis_var = choices_selected(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"), trt_group = choices_selected(c("ARM", "ACTARM"), "ARM"), color_manual = c( "150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C" ), color_comb = "#39ff14", comb_line = TRUE, plot_height = c(500, 200, 2000), font_size = c(12, 8, 20), line_size = c(1, .25, 3), hline_arb = c(.02, .05), hline_arb_color = c("red", "black"), hline_arb_label = c("Horizontal Line A", "Horizontal Line B") ) ) ) if (interactive()) { shinyApp(app$ui, app$server) } ``` </details>
- Loading branch information