From 4f90f9f26854fc64d516b41cd805150fc22a8a12 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:50:26 +0200 Subject: [PATCH] 249 remove analysis variable name plot title in spaghettiplot (#251) Close #249 Before the change title_before After the change after Tested with below ```r library(stringr) # original ARM value = dose value arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C") 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", trimws( substr( AVISIT, start = 6, stop = str_locate(AVISIT, "DAY") - 1 ) ) ), TRUE ~ NA_character_ )) %>% mutate(AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("\\D+", "", AVISITCD)), TRUE ~ NA_real_ )) %>% # use ARMCD values to order treatment in visualization legend mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, ifelse(grepl("B", ARMCD), 2, ifelse(grepl("A", ARMCD), 3, NA) ) )) %>% mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% mutate(ARM = factor(ARM) %>% reorder(TRTORD)) %>% mutate(ANRLO = .5, ANRHI = 1) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = .5, max = .7))), LBSTRESC )) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = .9, max = 1.2))), LBSTRESC )) %>% ungroup() attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit" attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit" # add LLOQ and ULOQ variables ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB, "LOQFL") ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM") g_spaghettiplot( data = ADLB, subj_id = "USUBJID", biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", time = "AVISITCD", color_manual = color_manual, color_comb = "#39ff14", alpha = .02, xtick = c("BL", "W 1", "W 4"), xlabel = c("Baseline", "Week 1", "Week 4"), rotate_xlab = FALSE, group_stats = "median", hline_vars = c("ANRHI", "ANRLO"), hline_vars_colors = c("pink", "brown") ) ``` --------- Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/g_spaghettiplot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/g_spaghettiplot.R b/R/g_spaghettiplot.R index 69d254e3..9046d69a 100644 --- a/R/g_spaghettiplot.R +++ b/R/g_spaghettiplot.R @@ -279,7 +279,7 @@ g_spaghettiplot <- function(data, select(!!sym(biomarker_var_label)) %>% unique() %>% magrittr::extract2(1) - gtitle <- paste0(biomarker1, unit1, value_var, " Values by Treatment @ Visits") + gtitle <- paste0(biomarker1, unit1, " Values by Treatment @ Visits") gxlab <- if (is.null(attr(data[[time]], "label"))) time else attr(data[[time]], "label") gylab <- paste0(biomarker1, " ", value_var, " Values")