Title: | R Package to Create TLGs |
---|---|
Description: | Community effort to collect TLG code and create a catalogue. |
Authors: | Nina Qi [aut, cre], Dawid Kaledkowski [aut], Chendi Liao [aut], Liming Li [aut], F. Hoffmann-La Roche AG [cph, fnd], Molly He [ctb], Carolyn Zhang [ctb], Tina Cho [ctb] |
Maintainer: | Nina Qi <[email protected]> |
License: | Apache License 2.0 | file LICENSE |
Version: | 0.1.16.9016 |
Built: | 2024-11-12 22:16:18 UTC |
Source: | https://github.com/insightsengineering/osprey |
gTree
) objects as PDFThis is an utility function to output a decorated grob (gTree
) object
as_pdf(grobs, outpath, pagesize = "letter.landscape")
as_pdf(grobs, outpath, pagesize = "letter.landscape")
grobs |
a grid grob ( |
outpath |
specify full path to output pdf to |
pagesize |
name of |
a pdf file
Chendi Liao (liaoc10) [email protected]
## Not run: library(ggplot2) g <- list( ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species)) + geom_point() ) ) # output to pdf as_pdf(g, "~/example_aspdf1.pdf") ## End(Not run)
## Not run: library(ggplot2) g <- list( ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species)) + geom_point() ) ) # output to pdf as_pdf(g, "~/example_aspdf1.pdf") ## End(Not run)
AE
overview flagscreate AE
overview flags
create_flag_vars( df, fatal = AESDTH == "Y", serious = AESER == "Y", serious_withdrawl = AESER == "Y" & grepl("DRUG WITHDRAWN", AEACN), serious_modified = AESER == "Y" & grepl("DRUG (INTERRUPTED|INCREASED|REDUCED)", AEACN), serious_related = AESER == "Y" & AEREL == "Y", withdrawl = grepl("DRUG WITHDRAWN", AEACN), modified = grepl("DRUG (INTERRUPTED|INCREASED|REDUCED)", AEACN), related = AEREL == "Y", related_withdrawl = AEREL == "Y" & grepl("DRUG WITHDRAWN", AEACN), related_modified = AEREL == "Y" & grepl("DRUG (INTERRUPTED|INCREASED|REDUCED)", AEACN), ctc35 = AETOXGR %in% c("3", "4", "5"), ... )
create_flag_vars( df, fatal = AESDTH == "Y", serious = AESER == "Y", serious_withdrawl = AESER == "Y" & grepl("DRUG WITHDRAWN", AEACN), serious_modified = AESER == "Y" & grepl("DRUG (INTERRUPTED|INCREASED|REDUCED)", AEACN), serious_related = AESER == "Y" & AEREL == "Y", withdrawl = grepl("DRUG WITHDRAWN", AEACN), modified = grepl("DRUG (INTERRUPTED|INCREASED|REDUCED)", AEACN), related = AEREL == "Y", related_withdrawl = AEREL == "Y" & grepl("DRUG WITHDRAWN", AEACN), related_modified = AEREL == "Y" & grepl("DRUG (INTERRUPTED|INCREASED|REDUCED)", AEACN), ctc35 = AETOXGR %in% c("3", "4", "5"), ... )
df |
data frame of |
fatal |
|
serious |
Serious |
serious_withdrawl |
Serious |
serious_modified |
Serious |
serious_related |
Related Serious |
withdrawl |
|
modified |
|
related |
Related |
related_withdrawl |
Related |
related_modified |
Related |
ctc35 |
Grade 3-5 |
... |
named expressions used to generate categories |
in this function, all flags are expressions calls, for simpler usage.
library(dplyr) ADAE <- osprey::rADAE # add additional dummy causality flags ADAE <- ADAE %>% mutate(AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X")) %>% mutate(AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")) attr(ADAE[["AEREL1"]], "label") <- "AE related to A: Drug X" attr(ADAE[["AEREL2"]], "label") <- "AE related to B: Placebo" create_flag_vars(ADAE) # create other flags create_flag_vars(ADAE, `AENSER` = AESER != "Y") # remove flags that are not needed create_flag_vars(ADAE, fatal = NULL)
library(dplyr) ADAE <- osprey::rADAE # add additional dummy causality flags ADAE <- ADAE %>% mutate(AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X")) %>% mutate(AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")) attr(ADAE[["AEREL1"]], "label") <- "AE related to A: Drug X" attr(ADAE[["AEREL2"]], "label") <- "AE related to B: Placebo" create_flag_vars(ADAE) # create other flags create_flag_vars(ADAE, `AENSER` = AESER != "Y") # remove flags that are not needed create_flag_vars(ADAE, fatal = NULL)
Draw adverse event category plot.
g_ae_sub( id, arm, arm_sl, subgroups, subgroups_sl, trt = levels(arm)[1], ref = levels(arm)[2], indent = 4, subgroups_levels = NULL, xmax = 0, conf_level = 0.95, diff_ci_method = c("wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "beal"), fontsize = 4, arm_n = FALSE, draw = TRUE )
g_ae_sub( id, arm, arm_sl, subgroups, subgroups_sl, trt = levels(arm)[1], ref = levels(arm)[2], indent = 4, subgroups_levels = NULL, xmax = 0, conf_level = 0.95, diff_ci_method = c("wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "beal"), fontsize = 4, arm_n = FALSE, draw = TRUE )
id |
( |
arm |
( |
arm_sl |
( |
subgroups |
( |
subgroups_sl |
( |
trt |
( |
ref |
( |
indent |
( |
subgroups_levels |
( |
xmax |
( |
conf_level |
( |
diff_ci_method |
( |
fontsize |
( |
arm_n |
( |
draw |
( |
there is no equivalent STREAM output
grob object
Liming Li (Lil128) [email protected]
library(grid) ADAE <- osprey::rADAE ADSL <- osprey::rADSL id <- ADAE$USUBJID arm <- ADAE$ACTARMCD arm_sl <- as.character(ADSL$ACTARMCD) subgroups_sl <- ADSL[, c("SEX", "RACE", "STRATA1")] subgroups <- ADAE[, c("SEX", "RACE", "STRATA1")] subgroups_levels <- list( RACE = list( "Total" = "Race", "AMERICAN INDIAN OR ALASKA NATIVE" = "American", "WHITE" = "White", "ASIAN" = "Asian", "BLACK OR AFRICAN AMERICAN" = "African" ), STRATA1 = list( "Total" = "Strata", "A" = "TypeA", "B" = "TypeB", "C" = "Typec" ), SEX = list( "Total" = "Sex", "M" = "Male", "F" = "Female" ) ) # Example 1 p1 <- g_ae_sub(id, arm, arm_sl, subgroups, subgroups_sl, trt = "ARM A", ref = "ARM C", subgroups_levels = subgroups_levels, arm_n = FALSE ) grid::grid.newpage() # Example 2: display number of patients in each arm p2 <- g_ae_sub(id, arm, arm_sl, subgroups, subgroups_sl, trt = "ARM A", ref = "ARM C", subgroups_levels = subgroups_levels, arm_n = TRUE ) grid::grid.newpage() # Example 3: preprocess data to only include treatment and control arm patients trt <- "ARM A" ref <- "ARM C" ADAE <- osprey::rADAE ADSL <- osprey::rADSL %>% filter(ACTARMCD %in% c(trt, ref)) id <- ADAE$USUBJID arm <- ADAE$ACTARMCD arm_sl <- as.character(ADSL$ACTARMCD) subgroups_sl <- ADSL[, c("SEX", "RACE", "STRATA1")] subgroups <- ADAE[, c("SEX", "RACE", "STRATA1")] subgroups_levels <- list( RACE = list( "Total" = "Race", "AMERICAN INDIAN OR ALASKA NATIVE" = "American", "WHITE" = "White", "ASIAN" = "Asian", "BLACK OR AFRICAN AMERICAN" = "African" ), STRATA1 = list( "Total" = "Strata", "A" = "TypeA", "B" = "TypeB", "C" = "Typec" ), SEX = list( "Total" = "Sex", "M" = "Male", "F" = "Female" ) ) p3 <- g_ae_sub(id, arm, arm_sl, subgroups, subgroups_sl, trt, ref, subgroups_levels = subgroups_levels, arm_n = FALSE )
library(grid) ADAE <- osprey::rADAE ADSL <- osprey::rADSL id <- ADAE$USUBJID arm <- ADAE$ACTARMCD arm_sl <- as.character(ADSL$ACTARMCD) subgroups_sl <- ADSL[, c("SEX", "RACE", "STRATA1")] subgroups <- ADAE[, c("SEX", "RACE", "STRATA1")] subgroups_levels <- list( RACE = list( "Total" = "Race", "AMERICAN INDIAN OR ALASKA NATIVE" = "American", "WHITE" = "White", "ASIAN" = "Asian", "BLACK OR AFRICAN AMERICAN" = "African" ), STRATA1 = list( "Total" = "Strata", "A" = "TypeA", "B" = "TypeB", "C" = "Typec" ), SEX = list( "Total" = "Sex", "M" = "Male", "F" = "Female" ) ) # Example 1 p1 <- g_ae_sub(id, arm, arm_sl, subgroups, subgroups_sl, trt = "ARM A", ref = "ARM C", subgroups_levels = subgroups_levels, arm_n = FALSE ) grid::grid.newpage() # Example 2: display number of patients in each arm p2 <- g_ae_sub(id, arm, arm_sl, subgroups, subgroups_sl, trt = "ARM A", ref = "ARM C", subgroups_levels = subgroups_levels, arm_n = TRUE ) grid::grid.newpage() # Example 3: preprocess data to only include treatment and control arm patients trt <- "ARM A" ref <- "ARM C" ADAE <- osprey::rADAE ADSL <- osprey::rADSL %>% filter(ACTARMCD %in% c(trt, ref)) id <- ADAE$USUBJID arm <- ADAE$ACTARMCD arm_sl <- as.character(ADSL$ACTARMCD) subgroups_sl <- ADSL[, c("SEX", "RACE", "STRATA1")] subgroups <- ADAE[, c("SEX", "RACE", "STRATA1")] subgroups_levels <- list( RACE = list( "Total" = "Race", "AMERICAN INDIAN OR ALASKA NATIVE" = "American", "WHITE" = "White", "ASIAN" = "Asian", "BLACK OR AFRICAN AMERICAN" = "African" ), STRATA1 = list( "Total" = "Strata", "A" = "TypeA", "B" = "TypeB", "C" = "Typec" ), SEX = list( "Total" = "Sex", "M" = "Male", "F" = "Female" ) ) p3 <- g_ae_sub(id, arm, arm_sl, subgroups, subgroups_sl, trt, ref, subgroups_levels = subgroups_levels, arm_n = FALSE )
The butterfly plot is often used in Early Development (ED) and is an opposed
barplot that shows instances of AE
s or # of patients by category separated by
a dichotomization variable. Each bar can be color coded according
to a variable of choice and sorted according to either alphabetical order or the
maximum count.
g_butterfly( category, right_flag, left_flag, id = NULL, group_names = NULL, block_count = c("# of patients", "# of AEs"), block_color = NULL, facet_rows = NULL, x_label = block_count, y_label = "AE Derived Terms", legend_label = "AETOXGR", sort_by = c("count", "alphabetical", "right", "left"), show_legend = TRUE )
g_butterfly( category, right_flag, left_flag, id = NULL, group_names = NULL, block_count = c("# of patients", "# of AEs"), block_color = NULL, facet_rows = NULL, x_label = block_count, y_label = "AE Derived Terms", legend_label = "AETOXGR", sort_by = c("count", "alphabetical", "right", "left"), show_legend = TRUE )
category |
vector of y values |
right_flag |
vector of |
left_flag |
vector of |
id |
unique subject identifier variable. |
group_names |
string vector of length 2 with desired names of dichotomization variables required format : first name corresponds to the name of the right side second name corresponds to name of the left side default: will extract column names from group |
block_count |
string - what to count by (ex: # of |
block_color |
vector - color coding of bar segments |
facet_rows |
vector defines what variable is used to split the plot into rows, default here is NULL |
x_label |
string of text for x axis label, default is block_count |
y_label |
string of text for y axis label, default is |
legend_label |
|
sort_by |
character string that defines the ordering of the class and term
variables in the output table,
options: |
show_legend |
|
there is no equivalent STREAM output
ggplot
object
Carolyn Zhang (zhanc107) [email protected]
Ting Qi (qit3) [email protected]
library(dplyr) library(nestcolor) ADSL <- osprey::rADSL %>% select(USUBJID, STUDYID, SEX, ARM, RACE) %>% dplyr::filter(SEX %in% c("F", "M")) ADAE <- osprey::rADAE %>% select(USUBJID, STUDYID, AEBODSYS, AETOXGR) ANL <- left_join(ADAE, ADSL, by = c("STUDYID", "USUBJID")) ANL <- ANL %>% dplyr::mutate(flag1 = ifelse(RACE == "ASIAN", 1, 0)) %>% dplyr::mutate(flag2 = ifelse(SEX == "M", 1, 0)) ANL <- na.omit(ANL) # Example 1, # of AEs g_butterfly( category = ANL$AEBODSYS, right_flag = ANL$flag1, left_flag = ANL$flag2, group_names = c("flag1 Asian", "flag2 M"), block_count = "# of AEs", block_color = ANL$AETOXGR, id = ANL$USUBJID, x_label = "# of AEs", y_label = "AE Body System", legend_label = "AETOXGR", sort_by = "count", show_legend = TRUE ) # Example 2, # of patients with facet g_butterfly( category = ANL$AEBODSYS, right_flag = ANL$flag1, left_flag = ANL$flag2, group_names = c("flag1 Asian", "flag2 M"), block_count = "# of patients", block_color = ANL$AETOXGR, facet_rows = ANL$ARM, id = ANL$USUBJID, x_label = "# of patients", y_label = "AE Derived Terms", legend_label = "AETOXGR", sort_by = "count", show_legend = TRUE )
library(dplyr) library(nestcolor) ADSL <- osprey::rADSL %>% select(USUBJID, STUDYID, SEX, ARM, RACE) %>% dplyr::filter(SEX %in% c("F", "M")) ADAE <- osprey::rADAE %>% select(USUBJID, STUDYID, AEBODSYS, AETOXGR) ANL <- left_join(ADAE, ADSL, by = c("STUDYID", "USUBJID")) ANL <- ANL %>% dplyr::mutate(flag1 = ifelse(RACE == "ASIAN", 1, 0)) %>% dplyr::mutate(flag2 = ifelse(SEX == "M", 1, 0)) ANL <- na.omit(ANL) # Example 1, # of AEs g_butterfly( category = ANL$AEBODSYS, right_flag = ANL$flag1, left_flag = ANL$flag2, group_names = c("flag1 Asian", "flag2 M"), block_count = "# of AEs", block_color = ANL$AETOXGR, id = ANL$USUBJID, x_label = "# of AEs", y_label = "AE Body System", legend_label = "AETOXGR", sort_by = "count", show_legend = TRUE ) # Example 2, # of patients with facet g_butterfly( category = ANL$AEBODSYS, right_flag = ANL$flag1, left_flag = ANL$flag2, group_names = c("flag1 Asian", "flag2 M"), block_count = "# of patients", block_color = ANL$AETOXGR, facet_rows = ANL$ARM, id = ANL$USUBJID, x_label = "# of patients", y_label = "AE Derived Terms", legend_label = "AETOXGR", sort_by = "count", show_legend = TRUE )
This function plots commonly occurred events by number of unique subjects with events. It creates basic summary of events and compares event occurrences between comparison and reference arms, and can be used for events data such as Adverse Events.
g_events_term_id( term, id, arm, arm_N, ref = levels(arm)[1], trt = levels(arm)[2], sort_by = c("term", "riskdiff", "meanrisk"), rate_range = c(0, 1), diff_range = c(-1, 1), reversed = FALSE, conf_level = 0.95, diff_ci_method = c("wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "beal"), axis_side = c("left", "right"), color = c(getOption("ggplot2.discrete.colour"), "blue", "red")[1:2], shape = c(16, 17), fontsize = 4, draw = TRUE )
g_events_term_id( term, id, arm, arm_N, ref = levels(arm)[1], trt = levels(arm)[2], sort_by = c("term", "riskdiff", "meanrisk"), rate_range = c(0, 1), diff_range = c(-1, 1), reversed = FALSE, conf_level = 0.95, diff_ci_method = c("wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "beal"), axis_side = c("left", "right"), color = c(getOption("ggplot2.discrete.colour"), "blue", "red")[1:2], shape = c(16, 17), fontsize = 4, draw = TRUE )
term |
|
id |
( |
arm |
( |
arm_N |
( |
ref |
|
trt |
|
sort_by |
|
rate_range |
Numeric |
diff_range |
Numeric |
reversed |
|
conf_level |
( |
diff_ci_method |
( |
axis_side |
|
color |
Color for the plot. |
shape |
Shape for the plot. |
fontsize |
( |
draw |
( |
there is no equivalent STREAM output
grob object
Liming Li (Lil128) [email protected]
Molly He (hey59) [email protected]
library(dplyr) library(grid) library(nestcolor) ADSL <- osprey::rADSL ADAE <- osprey::rADAE # add additional dummy causality flags ADAE <- ADAE %>% mutate(AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X")) %>% mutate(AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")) attr(ADAE[["AEREL1"]], "label") <- "AE related to A: Drug X" attr(ADAE[["AEREL2"]], "label") <- "AE related to B: Placebo" term <- ADAE$AEDECOD id <- ADAE$USUBJID arm <- ADAE$ACTARMCD arm_N <- table(ADSL$ACTARMCD) ref <- "ARM A" trt <- "ARM C" # Example 1 p1 <- g_events_term_id( term, id, arm, arm_N ) grid::grid.newpage() grid::grid.draw(p1) # Example 2 p2 <- g_events_term_id( term, id, arm, arm_N, trt = trt, ref = ref, sort_by = "riskdiff", diff_ci_method = "ac", conf_level = 0.9 ) grid::grid.newpage() grid::grid.draw(p2) # Example 3 p3 <- g_events_term_id( term, id, arm, arm_N, sort_by = "meanrisk", axis_side = "right", fontsize = 5 ) grid::grid.newpage() grid::grid.draw(p3) # Example 4 term <- create_flag_vars(ADAE) g_events_term_id( term, id, arm, arm_N, fontsize = 3 )
library(dplyr) library(grid) library(nestcolor) ADSL <- osprey::rADSL ADAE <- osprey::rADAE # add additional dummy causality flags ADAE <- ADAE %>% mutate(AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X")) %>% mutate(AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo")) attr(ADAE[["AEREL1"]], "label") <- "AE related to A: Drug X" attr(ADAE[["AEREL2"]], "label") <- "AE related to B: Placebo" term <- ADAE$AEDECOD id <- ADAE$USUBJID arm <- ADAE$ACTARMCD arm_N <- table(ADSL$ACTARMCD) ref <- "ARM A" trt <- "ARM C" # Example 1 p1 <- g_events_term_id( term, id, arm, arm_N ) grid::grid.newpage() grid::grid.draw(p1) # Example 2 p2 <- g_events_term_id( term, id, arm, arm_N, trt = trt, ref = ref, sort_by = "riskdiff", diff_ci_method = "ac", conf_level = 0.9 ) grid::grid.newpage() grid::grid.draw(p2) # Example 3 p3 <- g_events_term_id( term, id, arm, arm_N, sort_by = "meanrisk", axis_side = "right", fontsize = 5 ) grid::grid.newpage() grid::grid.draw(p3) # Example 4 term <- create_flag_vars(ADAE) g_events_term_id( term, id, arm, arm_N, fontsize = 3 )
This function plots heatmap
g_heat_bygrade( id_var, exp_data, visit_var, ongo_var, anno_data, anno_var, heat_data, heat_color_var, heat_color_opt = NULL, conmed_data = NULL, conmed_var = NULL, conmed_color_opt = NULL, xlab = "Visit", title = NULL )
g_heat_bygrade( id_var, exp_data, visit_var, ongo_var, anno_data, anno_var, heat_data, heat_color_var, heat_color_opt = NULL, conmed_data = NULL, conmed_var = NULL, conmed_color_opt = NULL, xlab = "Visit", title = NULL )
id_var |
( |
exp_data |
( |
visit_var |
( |
ongo_var |
( |
anno_data |
( |
anno_var |
( |
heat_data |
( |
heat_color_var |
( |
heat_color_opt |
optional, ( |
conmed_data |
optional, ( |
conmed_var |
optional, ( |
conmed_color_opt |
optional, ( |
xlab |
optional, ( |
title |
( |
Nina Qi (qit3) [email protected]
Molly He (hey59) [email protected]
library(dplyr) ADSL <- osprey::rADSL %>% slice(1:30) ADEX <- osprey::rADEX %>% filter(USUBJID %in% ADSL$USUBJID) ADAE <- osprey::rADAE %>% filter(USUBJID %in% ADSL$USUBJID) ADCM <- osprey::rADCM %>% filter(USUBJID %in% ADSL$USUBJID) # function to derive AVISIT from ADEX add_visit <- function(data_need_visit) { visit_dates <- ADEX %>% filter(PARAMCD == "DOSE") %>% distinct(USUBJID, AVISIT, ASTDTM) %>% group_by(USUBJID) %>% arrange(ASTDTM) %>% mutate(next_vis = lead(ASTDTM), is_last = ifelse(is.na(next_vis), TRUE, FALSE)) %>% rename(this_vis = ASTDTM) data_visit <- data_need_visit %>% select(USUBJID, ASTDTM) %>% left_join(visit_dates, by = "USUBJID", relationship = "many-to-many") %>% filter(ASTDTM > this_vis & (ASTDTM < next_vis | is_last == TRUE)) %>% left_join(data_need_visit, relationship = "many-to-many") return(data_visit) } # add AVISIT in ADAE and ADCM ADAE <- add_visit(ADAE) ADCM <- add_visit(ADCM) exp_data <- ADEX %>% filter(PARCAT1 == "INDIVIDUAL") %>% group_by(USUBJID) %>% # create a shorter subject identifier mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) %>% mutate(ongo_var = (EOSSTT == "ONGOING")) %>% ungroup() anno_data <- ADSL %>% select(SEX, COUNTRY, USUBJID) %>% group_by(USUBJID) %>% mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) %>% ungroup() %>% select(-USUBJID) heat_data <- ADAE %>% select(USUBJID, AVISIT, AETOXGR) %>% group_by(USUBJID) %>% mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) %>% ungroup() %>% select(-USUBJID) heat_color_opt <- c( "No Event" = "gray90", "1" = "lightsteelblue1", "2" = "steelblue1", "3" = "steelblue4", "4" = "maroon", "5" = "brown4" ) cmdecod_label <- attr(ADCM[["CMDECOD"]], "label") ADCM <- ADCM %>% filter( CMDECOD == "medname A_1/3" | CMDECOD == "medname A_2/3" | CMDECOD == "medname A_3/3" ) %>% mutate(CMDECOD = factor(CMDECOD, levels = unique(CMDECOD))) attr(ADCM[["CMDECOD"]], "label") <- cmdecod_label conmed_data <- ADCM %>% group_by(USUBJID) %>% mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) # example plotting conmed g_heat_bygrade( id_var = "SUBJ", exp_data, visit_var = "AVISIT", ongo_var = "ongo_var", anno_data, anno_var = c("SEX", "COUNTRY"), heat_data, heat_color_var = "AETOXGR", heat_color_opt, conmed_data, conmed_var = "CMDECOD", conmed_color_opt = c("green", "green3", "green4") ) # example not plotting conmed g_heat_bygrade( id_var = "SUBJ", exp_data, visit_var = "AVISIT", ongo_var = "ongo_var", anno_data, anno_var = c("SEX", "COUNTRY"), heat_data, heat_color_var = "AETOXGR", heat_color_opt )
library(dplyr) ADSL <- osprey::rADSL %>% slice(1:30) ADEX <- osprey::rADEX %>% filter(USUBJID %in% ADSL$USUBJID) ADAE <- osprey::rADAE %>% filter(USUBJID %in% ADSL$USUBJID) ADCM <- osprey::rADCM %>% filter(USUBJID %in% ADSL$USUBJID) # function to derive AVISIT from ADEX add_visit <- function(data_need_visit) { visit_dates <- ADEX %>% filter(PARAMCD == "DOSE") %>% distinct(USUBJID, AVISIT, ASTDTM) %>% group_by(USUBJID) %>% arrange(ASTDTM) %>% mutate(next_vis = lead(ASTDTM), is_last = ifelse(is.na(next_vis), TRUE, FALSE)) %>% rename(this_vis = ASTDTM) data_visit <- data_need_visit %>% select(USUBJID, ASTDTM) %>% left_join(visit_dates, by = "USUBJID", relationship = "many-to-many") %>% filter(ASTDTM > this_vis & (ASTDTM < next_vis | is_last == TRUE)) %>% left_join(data_need_visit, relationship = "many-to-many") return(data_visit) } # add AVISIT in ADAE and ADCM ADAE <- add_visit(ADAE) ADCM <- add_visit(ADCM) exp_data <- ADEX %>% filter(PARCAT1 == "INDIVIDUAL") %>% group_by(USUBJID) %>% # create a shorter subject identifier mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) %>% mutate(ongo_var = (EOSSTT == "ONGOING")) %>% ungroup() anno_data <- ADSL %>% select(SEX, COUNTRY, USUBJID) %>% group_by(USUBJID) %>% mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) %>% ungroup() %>% select(-USUBJID) heat_data <- ADAE %>% select(USUBJID, AVISIT, AETOXGR) %>% group_by(USUBJID) %>% mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) %>% ungroup() %>% select(-USUBJID) heat_color_opt <- c( "No Event" = "gray90", "1" = "lightsteelblue1", "2" = "steelblue1", "3" = "steelblue4", "4" = "maroon", "5" = "brown4" ) cmdecod_label <- attr(ADCM[["CMDECOD"]], "label") ADCM <- ADCM %>% filter( CMDECOD == "medname A_1/3" | CMDECOD == "medname A_2/3" | CMDECOD == "medname A_3/3" ) %>% mutate(CMDECOD = factor(CMDECOD, levels = unique(CMDECOD))) attr(ADCM[["CMDECOD"]], "label") <- cmdecod_label conmed_data <- ADCM %>% group_by(USUBJID) %>% mutate(SUBJ = utils::tail(strsplit(USUBJID, "-")[[1]], n = 1)) # example plotting conmed g_heat_bygrade( id_var = "SUBJ", exp_data, visit_var = "AVISIT", ongo_var = "ongo_var", anno_data, anno_var = c("SEX", "COUNTRY"), heat_data, heat_color_var = "AETOXGR", heat_color_opt, conmed_data, conmed_var = "CMDECOD", conmed_color_opt = c("green", "green3", "green4") ) # example not plotting conmed g_heat_bygrade( id_var = "SUBJ", exp_data, visit_var = "AVISIT", ongo_var = "ongo_var", anno_data, anno_var = c("SEX", "COUNTRY"), heat_data, heat_color_var = "AETOXGR", heat_color_opt )
A scatter plot typically used to display maximum total bilirubin values (TBL
)
versus maximum alanine transaminase (ALT
) values.
g_hy_law( id, term, aval, arm, term_selected, anrhi, folds = c(3, 2), text = c("Normal Range", "Hyperbilirubinemia", "Possible Hy's Law Range", "Temple's Corollary"), caption = paste("Maximum values are those maximum values that occur post-baseline", "(no time constraints and not necessarily concurrent events)."), title = "Max. Total Bilirubin vs. Max. Alanine Aminotransferase", xlab = "Maximum Alanine Aminotransferase (/ULN)", ylab = "Maximum Total Bilirubin (/ULN)" )
g_hy_law( id, term, aval, arm, term_selected, anrhi, folds = c(3, 2), text = c("Normal Range", "Hyperbilirubinemia", "Possible Hy's Law Range", "Temple's Corollary"), caption = paste("Maximum values are those maximum values that occur post-baseline", "(no time constraints and not necessarily concurrent events)."), title = "Max. Total Bilirubin vs. Max. Alanine Aminotransferase", xlab = "Maximum Alanine Aminotransferase (/ULN)", ylab = "Maximum Total Bilirubin (/ULN)" )
id |
unique subject identifier. |
term |
the term of the observation. |
aval |
analysis value. |
arm |
treatment arm. Used as fill color in the plot. |
term_selected |
string vector of length 2 - the two terms selected to be used in the plot. First value corresponds to parameter plotted on the x-axis. Second value corresponds to that plotted on the y-axis. |
anrhi |
the high limit of normal range. |
folds |
numeric vector of length two. Indicates the position of the reference lines to be drawn. Default c(3, 2) corresponds to a line at position 3 on the x-axis and 2 on the y-axis. |
text |
string vector of length four with the label to be shown on each quadrant. First value corresponds to label shown in the bottom left quadrant. Subsequent values move through the graph clockwise. |
caption |
string of text for footnote. Details of methodology can be shown here. |
title |
string of text for plot title. |
xlab |
string of text for x axis label. |
ylab |
string of text for y axis label. |
This graphic is based upon the eDISH
(evaluation of Drug Induced Serious
Hepatotoxicity) plot of Watkins et. al. in a 2008 publication from Hepatology.
Maximum values are defined as the maximum post-baseline value at any time
during the entire length of the observation period. Both axes are in log
scale to control for the dispersion of the data. The values are plotted in
'times upper limit of normal' where a value of 1 would mean that the result
was normal. Any value above or below 1 would be considered above the upper
limit or normal or below the upper limit of normal respectively. For
instance, a value of 3 would be read as '3 times the upper limit of normal'.
Reference lines are included to determine various states, based upon clinical
interpretation of the values and includes the following:
Hyperbilirubinemia TBL
at least 2 xULN
and ALT
less than 3 xULN
Normal Range TBL
<= 1 xULN
and ALT
<= 1 xULN
Temple’s Corollary TBL
<= 1 xULN
and ALT
at least 3 xULN
Possible Hy's Law TBL
at least 2 xULN
and ALT
at least 3 xULN
This plot can easily be adjusted for other lab parameters and reference ranges as needed. Consultation with a clinical expert to determine which associations would be clinically meaningful and how to interpret those associations is recommended.
There is no equivalent STREAM output.
plot object
Katie Withycombe (withycok) [email protected]
Amy Franklin (frankla4) [email protected]
William Holmes (holmesw) [email protected]
library(dplyr) library(nestcolor) # Note: CRP is being used in place of Bilirubin here because this is the only available data adsl <- osprey::rADSL adlb <- osprey::rADLB %>% mutate(ANRHI = 50) # Example 1, - Hy's law template (3 and 2 X ULN) g_hy_law( id = adlb$USUBJID, term = adlb$PARAMCD, aval = adlb$AVAL, arm = adlb$ARM, term_selected = c("ALT", "CRP"), anrhi = adlb$ANRHI, folds = c(3, 2), text = c("Normal Range", "Hyperbilirubinemia", "Possible Hy's Law Range", "Temple's Corollary"), caption = paste( "Maximum values are those maximum values that occur", "post-baseline (no time constraints and not necessarily concurrent events)." ), title = "Max. Total Bilirubin vs. Max. Alanine Aminotransferase", xlab = "Maximum Alanine Aminotransferase (/ULN)", ylab = "Maximum Total Bilirubin (/ULN)" ) # Example 2, - change the quadrant lines and labels g_hy_law( id = adlb$USUBJID, term = adlb$PARAMCD, aval = adlb$AVAL, arm = adlb$ARM, term_selected = c("ALT", "CRP"), anrhi = adlb$ANRHI, folds = c(10, 15), text = c("Quadrant 1", "Quadrant 2", "Quadrant 3", "Quadrant 4"), caption = paste( "Maximum values are those maximum values that occur", "post-baseline (no time constraints and not necessarily concurrent events)." ), title = "Max. Total Bilirubin vs. Max. Alanine Aminotransferase", xlab = "Maximum Alanine Aminotransferase (/ULN)", ylab = "Maximum Total Bilirubin (/ULN)" )
library(dplyr) library(nestcolor) # Note: CRP is being used in place of Bilirubin here because this is the only available data adsl <- osprey::rADSL adlb <- osprey::rADLB %>% mutate(ANRHI = 50) # Example 1, - Hy's law template (3 and 2 X ULN) g_hy_law( id = adlb$USUBJID, term = adlb$PARAMCD, aval = adlb$AVAL, arm = adlb$ARM, term_selected = c("ALT", "CRP"), anrhi = adlb$ANRHI, folds = c(3, 2), text = c("Normal Range", "Hyperbilirubinemia", "Possible Hy's Law Range", "Temple's Corollary"), caption = paste( "Maximum values are those maximum values that occur", "post-baseline (no time constraints and not necessarily concurrent events)." ), title = "Max. Total Bilirubin vs. Max. Alanine Aminotransferase", xlab = "Maximum Alanine Aminotransferase (/ULN)", ylab = "Maximum Total Bilirubin (/ULN)" ) # Example 2, - change the quadrant lines and labels g_hy_law( id = adlb$USUBJID, term = adlb$PARAMCD, aval = adlb$AVAL, arm = adlb$ARM, term_selected = c("ALT", "CRP"), anrhi = adlb$ANRHI, folds = c(10, 15), text = c("Quadrant 1", "Quadrant 2", "Quadrant 3", "Quadrant 4"), caption = paste( "Maximum values are those maximum values that occur", "post-baseline (no time constraints and not necessarily concurrent events)." ), title = "Max. Total Bilirubin vs. Max. Alanine Aminotransferase", xlab = "Maximum Alanine Aminotransferase (/ULN)", ylab = "Maximum Total Bilirubin (/ULN)" )
Patient profile plot provides detailed information for a specific subject participating in the study.
The plot includes relevant data for one subject that can help correlate adverse events, response,
concomitant medications, exposure, and laboratory. The plotting of patient profile is modularized, with
each domain plot generated by function patient_domain_profile
. This g_patient_profile
function assembles all requested domain plots into one patient profile.
ADSL
, ADEX
, ADAE
, ADRS
, ADCM
and ADLB
data must be provided.
The plot output will not include domains with data unspecified
g_patient_profile( ex = NULL, ae = NULL, rs = NULL, cm = NULL, lb = NULL, arrow_end_day, xlim = c(-28, 365), xlab = "Study Day", title = "Patient Profile" )
g_patient_profile( ex = NULL, ae = NULL, rs = NULL, cm = NULL, lb = NULL, arrow_end_day, xlim = c(-28, 365), xlab = "Study Day", title = "Patient Profile" )
ex |
list may contain
|
ae |
list may contain
|
rs |
list may contain
|
cm |
list may contain
|
lb |
list may contain
|
arrow_end_day |
numeric value indicates the end of arrow when arrows are requested |
xlim |
numeric vector for x-axis limit that will be shared by all domain plots, default is
|
xlab |
string to be shown as x-axis label, default is |
title |
string to be shown as title of the plot, default is |
plot object
Xuefeng Hou (houx14) [email protected]
Molly He (hey59) [email protected]
Ting Qi (qit3) [email protected]
library(dplyr) library(nestcolor) # ADSL ADSL <- osprey::rADSL %>% filter(USUBJID == rADSL$USUBJID[1]) %>% mutate( TRTSDT = as.Date(TRTSDTM), max_date = max(as.Date(LSTALVDT), as.Date(DTHDT), na.rm = TRUE), max_day = as.numeric(as.Date(max_date) - as.Date(TRTSDT)) + 1 ) %>% select(USUBJID, STUDYID, TRTSDT, max_day) # ADEX ADEX <- osprey::rADEX %>% select(USUBJID, STUDYID, ASTDTM, PARCAT2, AVAL, AVALU, PARAMCD) ADEX <- left_join(ADSL, ADEX, by = c("USUBJID", "STUDYID")) ADEX <- ADEX %>% filter(PARAMCD == "DOSE") %>% arrange(PARCAT2, PARAMCD) %>% mutate(diff = c(0, diff(AVAL, lag = 1))) %>% mutate(Modification = case_when( diff < 0 ~ "Decrease", diff > 0 ~ "Increase", diff == 0 ~ "None" )) %>% mutate(ASTDT_dur = as.numeric( as.Date(substr(as.character(ASTDTM), 1, 10)) - as.Date(TRTSDT) + 1 )) # ADAE ADAE <- osprey::rADAE %>% select(USUBJID, STUDYID, AESOC, AEDECOD, AESER, AETOXGR, AEREL, ASTDY, AENDY) ADAE <- left_join(ADSL, ADAE, by = c("USUBJID", "STUDYID")) # ADRS ADRS <- osprey::rADRS %>% select(USUBJID, STUDYID, PARAMCD, PARAM, AVALC, AVAL, ADY, ADTM) ADRS <- left_join(ADSL, ADRS, by = c("USUBJID", "STUDYID")) # ADCM ADCM <- osprey::rADCM %>% select(USUBJID, STUDYID, ASTDTM, AENDTM, CMDECOD, ASTDY, AENDY) ADCM <- left_join(ADSL, ADCM, by = c("USUBJID", "STUDYID")) # ADLB ADLB <- osprey::rADLB %>% select( USUBJID, STUDYID, LBSEQ, PARAMCD, BASETYPE, ADTM, ADY, ATPTN, AVISITN, LBTESTCD, ANRIND ) ADLB <- left_join(ADSL, ADLB, by = c("USUBJID", "STUDYID")) ADLB <- ADLB %>% group_by(USUBJID) %>% mutate(ANRIND = factor(ANRIND, levels = c("LOW", "NORMAL", "HIGH"))) # Example Patient Profile plot 5 domains g_patient_profile( ex = list( data = ADEX, var = ADEX$PARCAT2 ), ae = list( data = ADAE, var = ADAE$AEDECOD, line_col = factor(ADAE$AESER), line_col_legend = "Serious", line_col_opt = c("Y" = "red", "N" = "blue") ), rs = list( data = ADRS, var = ADRS$PARAMCD ), cm = list( data = ADCM, var = ADCM$CMDECOD ), lb = list( data = ADLB, var = ADLB$LBTESTCD ), arrow_end_day = ADSL$max_day, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) # Example Patient Profile plot without ADCM and ADLB g_patient_profile( ex = list( data = ADEX, var = ADEX$PARCAT2 ), ae = list( data = ADAE, var = ADAE$AEDECOD, line_col = factor(ADAE$AESER), line_col_legend = "Serious", line_col_opt = c("Y" = "red", "N" = "blue") ), rs = list( data = ADRS, var = ADRS$PARAMCD ), arrow_end_day = ADSL$max_day, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) )
library(dplyr) library(nestcolor) # ADSL ADSL <- osprey::rADSL %>% filter(USUBJID == rADSL$USUBJID[1]) %>% mutate( TRTSDT = as.Date(TRTSDTM), max_date = max(as.Date(LSTALVDT), as.Date(DTHDT), na.rm = TRUE), max_day = as.numeric(as.Date(max_date) - as.Date(TRTSDT)) + 1 ) %>% select(USUBJID, STUDYID, TRTSDT, max_day) # ADEX ADEX <- osprey::rADEX %>% select(USUBJID, STUDYID, ASTDTM, PARCAT2, AVAL, AVALU, PARAMCD) ADEX <- left_join(ADSL, ADEX, by = c("USUBJID", "STUDYID")) ADEX <- ADEX %>% filter(PARAMCD == "DOSE") %>% arrange(PARCAT2, PARAMCD) %>% mutate(diff = c(0, diff(AVAL, lag = 1))) %>% mutate(Modification = case_when( diff < 0 ~ "Decrease", diff > 0 ~ "Increase", diff == 0 ~ "None" )) %>% mutate(ASTDT_dur = as.numeric( as.Date(substr(as.character(ASTDTM), 1, 10)) - as.Date(TRTSDT) + 1 )) # ADAE ADAE <- osprey::rADAE %>% select(USUBJID, STUDYID, AESOC, AEDECOD, AESER, AETOXGR, AEREL, ASTDY, AENDY) ADAE <- left_join(ADSL, ADAE, by = c("USUBJID", "STUDYID")) # ADRS ADRS <- osprey::rADRS %>% select(USUBJID, STUDYID, PARAMCD, PARAM, AVALC, AVAL, ADY, ADTM) ADRS <- left_join(ADSL, ADRS, by = c("USUBJID", "STUDYID")) # ADCM ADCM <- osprey::rADCM %>% select(USUBJID, STUDYID, ASTDTM, AENDTM, CMDECOD, ASTDY, AENDY) ADCM <- left_join(ADSL, ADCM, by = c("USUBJID", "STUDYID")) # ADLB ADLB <- osprey::rADLB %>% select( USUBJID, STUDYID, LBSEQ, PARAMCD, BASETYPE, ADTM, ADY, ATPTN, AVISITN, LBTESTCD, ANRIND ) ADLB <- left_join(ADSL, ADLB, by = c("USUBJID", "STUDYID")) ADLB <- ADLB %>% group_by(USUBJID) %>% mutate(ANRIND = factor(ANRIND, levels = c("LOW", "NORMAL", "HIGH"))) # Example Patient Profile plot 5 domains g_patient_profile( ex = list( data = ADEX, var = ADEX$PARCAT2 ), ae = list( data = ADAE, var = ADAE$AEDECOD, line_col = factor(ADAE$AESER), line_col_legend = "Serious", line_col_opt = c("Y" = "red", "N" = "blue") ), rs = list( data = ADRS, var = ADRS$PARAMCD ), cm = list( data = ADCM, var = ADCM$CMDECOD ), lb = list( data = ADLB, var = ADLB$LBTESTCD ), arrow_end_day = ADSL$max_day, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) # Example Patient Profile plot without ADCM and ADLB g_patient_profile( ex = list( data = ADEX, var = ADEX$PARCAT2 ), ae = list( data = ADAE, var = ADAE$AEDECOD, line_col = factor(ADAE$AESER), line_col_legend = "Serious", line_col_opt = c("Y" = "red", "N" = "blue") ), rs = list( data = ADRS, var = ADRS$PARAMCD ), arrow_end_day = ADSL$max_day, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) )
Spider plot is often used in Early Development (ED) and displays individual patient plot of an endpoint over time by group.
g_spiderplot( marker_x, marker_id, marker_y, line_colby = NULL, line_color_opt = NULL, marker_shape = NULL, marker_shape_opt = NULL, marker_size = 3, datalabel_txt = NULL, facet_rows = NULL, facet_columns = NULL, vref_line = NULL, href_line = NULL, x_label = "Time (Days)", y_label = "Change (%) from Baseline", show_legend = FALSE )
g_spiderplot( marker_x, marker_id, marker_y, line_colby = NULL, line_color_opt = NULL, marker_shape = NULL, marker_shape_opt = NULL, marker_size = 3, datalabel_txt = NULL, facet_rows = NULL, facet_columns = NULL, vref_line = NULL, href_line = NULL, x_label = "Time (Days)", y_label = "Change (%) from Baseline", show_legend = FALSE )
marker_x |
vector of x values (must be in sorted order) |
marker_id |
vector to group the points together (default
should be |
marker_y |
vector of y values |
line_colby |
vector defines by what variable plot is color coded,
default here is |
line_color_opt |
vector defines line color, default here is |
marker_shape |
vector defines by what variable points are shape coded,
, default here is |
marker_shape_opt |
vector defines marker shape code, default here is |
marker_size |
size of markers in plot, default here is |
datalabel_txt |
list defines text (at last time point) and flag for an arrow annotation:
|
facet_rows |
dataframe defines what variable is used to split the
plot into rows, default here is |
facet_columns |
dataframe defines what variable is used to split the
plot into columns, default here is |
vref_line |
value defines vertical line overlay
(can be a vector), default here is |
href_line |
value defines horizontal line overlay
(can be a vector), default here is |
x_label |
string of text for x axis label, default is time. |
y_label |
string of text for y axis label, default is % change. |
show_legend |
boolean of whether marker legend is included, default here is |
there is no equivalent STREAM output
ggplot
object
Carolyn Zhang (zhanc107) [email protected]
# simple example library(dplyr) library(nestcolor) ADTR <- osprey::rADTR %>% select(STUDYID, USUBJID, ADY, AVISIT, CHG, PCHG, PARAMCD) ADSL <- osprey::rADSL %>% select(STUDYID, USUBJID, RACE, SEX, ARM) ANL <- left_join(ADTR, ADSL, by = c("STUDYID", "USUBJID")) ANL <- ANL %>% dplyr::filter(PARAMCD == "SLDINV" & AVISIT != "POST-BASELINE MINIMUM") %>% dplyr::filter(RACE %in% c("WHITE", "ASIAN")) %>% group_by(USUBJID) %>% dplyr::arrange(ADY) %>% dplyr::mutate( CHG = ifelse(AVISIT == "Screening", 0, CHG), PCHG = ifelse(AVISIT == "Screening", 0, PCHG) ) ANL$USUBJID <- substr(ANL$USUBJID, 14, 18) # Plot 1 - default color and shape mapping g_spiderplot( marker_x = ANL$ADY, marker_id = ANL$USUBJID, marker_y = ANL$PCHG, line_colby = ANL$USUBJID, marker_shape = ANL$USUBJID, # marker_size = 5, datalabel_txt = list(txt_ann = ANL$USUBJID), # facet_rows = data.frame(sex = ANL$SEX), # facet_columns = data.frame(arm = ANL$ARM), vref_line = c(42, 86), href_line = c(-20, 20), x_label = "Time (Days)", y_label = "Change (%) from Baseline", show_legend = TRUE ) # Plot 2 - with line color mapping g_spiderplot( marker_x = ANL$AVISIT, marker_id = ANL$USUBJID, marker_y = ANL$CHG, line_colby = ANL$RACE, line_color_opt = c("WHITE" = "red", "ASIAN" = "blue"), marker_shape = ANL$USUBJID, x_label = "Visit", y_label = "Change from Baseline", show_legend = TRUE )
# simple example library(dplyr) library(nestcolor) ADTR <- osprey::rADTR %>% select(STUDYID, USUBJID, ADY, AVISIT, CHG, PCHG, PARAMCD) ADSL <- osprey::rADSL %>% select(STUDYID, USUBJID, RACE, SEX, ARM) ANL <- left_join(ADTR, ADSL, by = c("STUDYID", "USUBJID")) ANL <- ANL %>% dplyr::filter(PARAMCD == "SLDINV" & AVISIT != "POST-BASELINE MINIMUM") %>% dplyr::filter(RACE %in% c("WHITE", "ASIAN")) %>% group_by(USUBJID) %>% dplyr::arrange(ADY) %>% dplyr::mutate( CHG = ifelse(AVISIT == "Screening", 0, CHG), PCHG = ifelse(AVISIT == "Screening", 0, PCHG) ) ANL$USUBJID <- substr(ANL$USUBJID, 14, 18) # Plot 1 - default color and shape mapping g_spiderplot( marker_x = ANL$ADY, marker_id = ANL$USUBJID, marker_y = ANL$PCHG, line_colby = ANL$USUBJID, marker_shape = ANL$USUBJID, # marker_size = 5, datalabel_txt = list(txt_ann = ANL$USUBJID), # facet_rows = data.frame(sex = ANL$SEX), # facet_columns = data.frame(arm = ANL$ARM), vref_line = c(42, 86), href_line = c(-20, 20), x_label = "Time (Days)", y_label = "Change (%) from Baseline", show_legend = TRUE ) # Plot 2 - with line color mapping g_spiderplot( marker_x = ANL$AVISIT, marker_id = ANL$USUBJID, marker_y = ANL$CHG, line_colby = ANL$RACE, line_color_opt = c("WHITE" = "red", "ASIAN" = "blue"), marker_shape = ANL$USUBJID, x_label = "Visit", y_label = "Change from Baseline", show_legend = TRUE )
Swimlane
PlotSwimlane
plot is often used in Early Development (ED) and displays individual
patient bar plot with markers of events and patient level annotation
g_swimlane( bar_id, bar_length, sort_by = NULL, col_by = NULL, marker_id = NULL, marker_pos = NULL, marker_shape = NULL, marker_shape_opt = NULL, marker_color = NULL, marker_color_opt = NULL, anno_txt = NULL, xref_line = NULL, xtick_at = waiver(), xlab, title )
g_swimlane( bar_id, bar_length, sort_by = NULL, col_by = NULL, marker_id = NULL, marker_pos = NULL, marker_shape = NULL, marker_shape_opt = NULL, marker_color = NULL, marker_color_opt = NULL, anno_txt = NULL, xref_line = NULL, xtick_at = waiver(), xlab, title )
bar_id |
vector of IDs to identify each bar |
bar_length |
numeric vector to be plotted as length for each bar |
sort_by |
vector to sort bars |
col_by |
vector to color bars |
marker_id |
vector of IDs to identify markers within each bar. Default is the same as bar_id. |
marker_pos |
numeric vector to specify position for each marker point |
marker_shape |
vector to specify shape for markers |
marker_shape_opt |
aesthetic values to map shape values (named vector to map shape values to each name) |
marker_color |
vector to specify color for markers |
marker_color_opt |
aesthetic values to map shape values (named vector to map shape values to each name) |
anno_txt |
dataframe of subject-level variables to be displayed as annotation on the left |
xref_line |
numeric vector to plot reference lines |
xtick_at |
optional break interval of bar length axis |
xlab |
label for bar length |
title |
string to be displayed as plot title |
plot object
Ting Qi (qit3) [email protected]
# Example 1 library(dplyr) library(nestcolor) ADSL <- osprey::rADSL[1:20, ] ADRS <- filter(rADRS, PARAMCD == "OVRINV") ANL <- left_join(ADSL, ADRS, by = c("STUDYID", "USUBJID"), multiple = "all") anno_txt <- ADSL[, c("ARMCD", "SEX")] g_swimlane( bar_id = ADSL$USUBJID, bar_length = as.integer(ADSL$TRTEDTM - ADSL$TRTSDTM), sort_by = ADSL$ARM, col_by = ADSL$ARM, marker_id = ANL$USUBJID, marker_pos = ANL$ADY, marker_shape = ANL$AVALC, marker_shape_opt = c("CR" = 16, "PR" = 17, "SD" = 18, "PD" = 15, "NE" = 4), marker_color = NULL, marker_color_opt = NULL, anno_txt = anno_txt, xref_line = c(50, 100), xtick_at = waiver(), xlab = "Time from First Treatment (Day)", title = "Swimlane Plot" ) # Example 2 library(dplyr) library(nestcolor) ADSL <- osprey::rADSL[1:20, ] ADRS <- osprey::rADRS anno_txt_vars <- c("ARMCD", "SEX", "COUNTRY") anno_txt <- ADSL[, anno_txt_vars] # markers from ADRS ADRS <- dplyr::filter(ADRS, PARAMCD == "OVRINV") %>% select(USUBJID, ADY, AVALC) # markers from ADSL - discontinuation ADS <- ADSL %>% dplyr::filter(EOSSTT == "Discontinued" | DCSREAS != "") %>% select(USUBJID, EOSDY, DCSREAS) %>% dplyr::rename(ADY = EOSDY, AVALC = DCSREAS) # combine ADRS with ADS records as one data for markers and join with ADSL ANL <- inner_join(ADSL, rbind(ADRS, ADS), by = "USUBJID", multiple = "all") g_swimlane( bar_id = sub(".*-", "", ADSL$USUBJID), bar_length = as.integer(ADSL$TRTEDTM - ADSL$TRTSDTM), sort_by = NULL, col_by = ADSL$ARMCD, marker_id = sub(".*-", "", ANL$USUBJID), marker_pos = ANL$ADY, marker_shape = ANL$AVALC, marker_shape_opt = c( "CR" = 16, "PR" = 17, "SD" = 18, "PD" = 15, "NE" = 0, "Adverse Event" = 7, "Death" = 8, "Physician Decision" = 9, "Progressive Disease" = 10, "Symptomatic Deterioation" = 11, "Withdrawal by Subject" = 12 ), marker_color = ANL$AVALC, marker_color_opt = c( "CR" = "green", "PR" = "blue", "SD" = "yellow", "PD" = "red", "NE" = "grey", "Adverse Event" = "orange", "Death" = "black", "Physician Decision" = "navy", "Progressive Disease" = "purple", "Symptomatic Deterioation" = "cyan", "Withdrawal by Subject" = "darkred" ), anno_txt = anno_txt, xref_line = c(50, 100), xtick_at = waiver(), xlab = "Time from First Treatment (Day)", title = "Swimlane Plot" )
# Example 1 library(dplyr) library(nestcolor) ADSL <- osprey::rADSL[1:20, ] ADRS <- filter(rADRS, PARAMCD == "OVRINV") ANL <- left_join(ADSL, ADRS, by = c("STUDYID", "USUBJID"), multiple = "all") anno_txt <- ADSL[, c("ARMCD", "SEX")] g_swimlane( bar_id = ADSL$USUBJID, bar_length = as.integer(ADSL$TRTEDTM - ADSL$TRTSDTM), sort_by = ADSL$ARM, col_by = ADSL$ARM, marker_id = ANL$USUBJID, marker_pos = ANL$ADY, marker_shape = ANL$AVALC, marker_shape_opt = c("CR" = 16, "PR" = 17, "SD" = 18, "PD" = 15, "NE" = 4), marker_color = NULL, marker_color_opt = NULL, anno_txt = anno_txt, xref_line = c(50, 100), xtick_at = waiver(), xlab = "Time from First Treatment (Day)", title = "Swimlane Plot" ) # Example 2 library(dplyr) library(nestcolor) ADSL <- osprey::rADSL[1:20, ] ADRS <- osprey::rADRS anno_txt_vars <- c("ARMCD", "SEX", "COUNTRY") anno_txt <- ADSL[, anno_txt_vars] # markers from ADRS ADRS <- dplyr::filter(ADRS, PARAMCD == "OVRINV") %>% select(USUBJID, ADY, AVALC) # markers from ADSL - discontinuation ADS <- ADSL %>% dplyr::filter(EOSSTT == "Discontinued" | DCSREAS != "") %>% select(USUBJID, EOSDY, DCSREAS) %>% dplyr::rename(ADY = EOSDY, AVALC = DCSREAS) # combine ADRS with ADS records as one data for markers and join with ADSL ANL <- inner_join(ADSL, rbind(ADRS, ADS), by = "USUBJID", multiple = "all") g_swimlane( bar_id = sub(".*-", "", ADSL$USUBJID), bar_length = as.integer(ADSL$TRTEDTM - ADSL$TRTSDTM), sort_by = NULL, col_by = ADSL$ARMCD, marker_id = sub(".*-", "", ANL$USUBJID), marker_pos = ANL$ADY, marker_shape = ANL$AVALC, marker_shape_opt = c( "CR" = 16, "PR" = 17, "SD" = 18, "PD" = 15, "NE" = 0, "Adverse Event" = 7, "Death" = 8, "Physician Decision" = 9, "Progressive Disease" = 10, "Symptomatic Deterioation" = 11, "Withdrawal by Subject" = 12 ), marker_color = ANL$AVALC, marker_color_opt = c( "CR" = "green", "PR" = "blue", "SD" = "yellow", "PD" = "red", "NE" = "grey", "Adverse Event" = "orange", "Death" = "black", "Physician Decision" = "navy", "Progressive Disease" = "purple", "Symptomatic Deterioation" = "cyan", "Withdrawal by Subject" = "darkred" ), anno_txt = anno_txt, xref_line = c(50, 100), xtick_at = waiver(), xlab = "Time from First Treatment (Day)", title = "Swimlane Plot" )
Waterfall plot is often used in Early Development (ED) to present each individual patient’s best response to a particular drug based on a parameter.
g_waterfall( bar_id, bar_height, sort_by = NULL, col_by = NULL, bar_color_opt = NULL, anno_txt = NULL, href_line = NULL, facet_by = NULL, show_datavalue = TRUE, add_label = NULL, gap_point = NULL, ytick_at = 20, y_label = "Best % Change from Baseline", title = "Waterfall Plot" )
g_waterfall( bar_id, bar_height, sort_by = NULL, col_by = NULL, bar_color_opt = NULL, anno_txt = NULL, href_line = NULL, facet_by = NULL, show_datavalue = TRUE, add_label = NULL, gap_point = NULL, ytick_at = 20, y_label = "Best % Change from Baseline", title = "Waterfall Plot" )
bar_id |
( |
bar_height |
numeric vector to be plotted as height of each bar |
sort_by |
( |
col_by |
( |
bar_color_opt |
( |
anno_txt |
( |
href_line |
( |
facet_by |
( |
show_datavalue |
( |
add_label |
( |
gap_point |
( |
ytick_at |
( |
y_label |
( |
title |
( |
plot object
Xuefeng Hou (houx14) [email protected]
Ting Qi (qit3) [email protected]
library(tidyr) library(dplyr) library(nestcolor) g_waterfall( bar_id = letters[1:3], bar_height = c(3, 5, -1), bar_color_opt = c("red", "green", "blue") ) # Example 1 ADSL <- osprey::rADSL[1:15, ] ADRS <- osprey::rADRS %>% filter(USUBJID %in% ADSL$USUBJID) ADTR <- osprey::rADTR %>% filter(USUBJID %in% ADSL$USUBJID) %>% select(USUBJID, PCHG) %>% group_by(USUBJID) %>% slice(which.min(PCHG)) TR_SL <- inner_join(ADSL, ADTR, by = "USUBJID", multiple = "all") SUB_ADRS <- ADRS %>% filter(PARAMCD == "BESRSPI" | PARAMCD == "INVET") %>% select(USUBJID, PARAMCD, AVALC, AVISIT, ADY) %>% spread(PARAMCD, AVALC) ANL <- TR_SL %>% left_join(SUB_ADRS, by = "USUBJID", multiple = "all") %>% mutate(TRTDURD = as.integer(TRTEDTM - TRTSDTM) + 1) anno_txt_vars <- c("TRTDURD", "BESRSPI", "INVET", "SEX", "BMRKR2") g_waterfall( bar_height = ANL$PCHG, bar_id = sub(".*-", "", ANL$USUBJID), col_by = ANL$SEX, sort_by = ANL$ARM, # bar_color_opt = c("F" = "red", "M" = "green", "U" = "blue"), anno_txt = ANL[, anno_txt_vars], facet_by = NULL, href_line = c(-30, 20), add_label = ANL$BESRSPI, ytick_at = 20, gap_point = NULL, show_datavalue = TRUE, y_label = "Best % Change from Baseline", title = "Waterfall Plot" ) # Example 2 facetting anno_txt_vars <- c("BESRSPI", "INVET") g_waterfall( bar_id = sub(".*-", "", ANL$USUBJID), bar_height = ANL$PCHG, sort_by = ANL$COUNTRY, col_by = ANL$SEX, bar_color_opt = c("F" = "tomato", "M" = "skyblue3", "U" = "darkgreen"), anno_txt = ANL[, anno_txt_vars], facet_by = ANL$STRATA2, href_line = c(-30, 20), add_label = ANL$BESRSPI, ytick_at = 20, gap_point = 260, y_label = "Best % Change from Baseline", title = "Waterfall Plot" ) # Example 3 extreme value ANL$PCHG[3] <- 99 ANL$PCHG[5] <- 199 ANL$PCHG[7] <- 599 ANL$BESRSPI[3] <- "PD" ANL$BESRSPI[5] <- "PD" ANL$BESRSPI[7] <- "PD" g_waterfall( bar_id = sub(".*-", "", ANL$USUBJID), bar_height = ANL$PCHG, sort_by = ANL$ARM, col_by = ANL$SEX, bar_color_opt = c("F" = "tomato", "M" = "skyblue3", "U" = "darkgreen"), anno_txt = ANL[, anno_txt_vars], facet_by = NULL, href_line = c(-30, 20), add_label = ANL$BESRSPI, ytick_at = 20, gap_point = 260, y_label = "Best % Change from Baseline", title = "Waterfall Plot" )
library(tidyr) library(dplyr) library(nestcolor) g_waterfall( bar_id = letters[1:3], bar_height = c(3, 5, -1), bar_color_opt = c("red", "green", "blue") ) # Example 1 ADSL <- osprey::rADSL[1:15, ] ADRS <- osprey::rADRS %>% filter(USUBJID %in% ADSL$USUBJID) ADTR <- osprey::rADTR %>% filter(USUBJID %in% ADSL$USUBJID) %>% select(USUBJID, PCHG) %>% group_by(USUBJID) %>% slice(which.min(PCHG)) TR_SL <- inner_join(ADSL, ADTR, by = "USUBJID", multiple = "all") SUB_ADRS <- ADRS %>% filter(PARAMCD == "BESRSPI" | PARAMCD == "INVET") %>% select(USUBJID, PARAMCD, AVALC, AVISIT, ADY) %>% spread(PARAMCD, AVALC) ANL <- TR_SL %>% left_join(SUB_ADRS, by = "USUBJID", multiple = "all") %>% mutate(TRTDURD = as.integer(TRTEDTM - TRTSDTM) + 1) anno_txt_vars <- c("TRTDURD", "BESRSPI", "INVET", "SEX", "BMRKR2") g_waterfall( bar_height = ANL$PCHG, bar_id = sub(".*-", "", ANL$USUBJID), col_by = ANL$SEX, sort_by = ANL$ARM, # bar_color_opt = c("F" = "red", "M" = "green", "U" = "blue"), anno_txt = ANL[, anno_txt_vars], facet_by = NULL, href_line = c(-30, 20), add_label = ANL$BESRSPI, ytick_at = 20, gap_point = NULL, show_datavalue = TRUE, y_label = "Best % Change from Baseline", title = "Waterfall Plot" ) # Example 2 facetting anno_txt_vars <- c("BESRSPI", "INVET") g_waterfall( bar_id = sub(".*-", "", ANL$USUBJID), bar_height = ANL$PCHG, sort_by = ANL$COUNTRY, col_by = ANL$SEX, bar_color_opt = c("F" = "tomato", "M" = "skyblue3", "U" = "darkgreen"), anno_txt = ANL[, anno_txt_vars], facet_by = ANL$STRATA2, href_line = c(-30, 20), add_label = ANL$BESRSPI, ytick_at = 20, gap_point = 260, y_label = "Best % Change from Baseline", title = "Waterfall Plot" ) # Example 3 extreme value ANL$PCHG[3] <- 99 ANL$PCHG[5] <- 199 ANL$PCHG[7] <- 599 ANL$BESRSPI[3] <- "PD" ANL$BESRSPI[5] <- "PD" ANL$BESRSPI[7] <- "PD" g_waterfall( bar_id = sub(".*-", "", ANL$USUBJID), bar_height = ANL$PCHG, sort_by = ANL$ARM, col_by = ANL$SEX, bar_color_opt = c("F" = "tomato", "M" = "skyblue3", "U" = "darkgreen"), anno_txt = ANL[, anno_txt_vars], facet_by = NULL, href_line = c(-30, 20), add_label = ANL$BESRSPI, ytick_at = 20, gap_point = 260, y_label = "Best % Change from Baseline", title = "Waterfall Plot" )
gTree
) objects then outputs as IDM
compatible PDFThis is an utility function to decorated grob (gTree
) object with titles and
footnotes in accordance with IDM
specification and export as PDF file with
full path to program and the output for easy tracking and archiving.
grobs2pdf( grobs, titles, footnotes, progpath, outpath, fontsize = 9, pagesize = "letter.landscape" )
grobs2pdf( grobs, titles, footnotes, progpath, outpath, fontsize = 9, pagesize = "letter.landscape" )
grobs |
A grid grob ( |
titles |
Vector of character strings. Vector elements are separated by a newline and strings are wrapped according to the page with |
footnotes |
Vector of character string. Same rules as for |
progpath |
Specify the full path to the R program that generate the grobs and the PDF |
outpath |
Specify full path to output pdf to |
fontsize |
Base font size used in pdf, default set to 9. Font size for
title is set to |
pagesize |
name of paper size and orientation, accepted values include
|
a pdf file
Chendi Liao (liaoc10) [email protected]
## Not run: library(ggplot2) g <- list( ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species)) + geom_point() ) ) grobs2pdf( grobs = g, titles = "Visualization of Iris Data", footnotes = "This is a footnote", progpath = "~/example_prog.R", outpath = "~/example_grobs2pdf.pdf" ) ## End(Not run)
## Not run: library(ggplot2) g <- list( ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point() ), ggplotGrob( ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species)) + geom_point() ) ) grobs2pdf( grobs = g, titles = "Visualization of Iris Data", footnotes = "This is a footnote", progpath = "~/example_prog.R", outpath = "~/example_grobs2pdf.pdf" ) ## End(Not run)
Patient domain profile provides information for a specific subject that participated in the study.
The plot includes relevant data for one subject in a user specified domain, including
adverse events (ADAE
), response (ADRS
), concomitant medications
(ADCM
), exposure (ADEX
), and laboratory (ADLB
).
patient_domain_profile( domain = NULL, var_names, marker_pos, arrow_end, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = NULL, marker_shape_list = NULL, show_days_label = TRUE, xlim = c(-28, max(marker_pos) + 5), xlab = NULL, show_title = TRUE, title = NULL )
patient_domain_profile( domain = NULL, var_names, marker_pos, arrow_end, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = NULL, marker_shape_list = NULL, show_days_label = TRUE, xlim = c(-28, max(marker_pos) + 5), xlab = NULL, show_title = TRUE, title = NULL )
domain |
string of domain name to be shown as y-axis label, default is |
var_names |
character vector to identify each lane |
marker_pos |
Depending on the domain, this can be
|
arrow_end |
numeric value indicates the end of arrow when arrows are requested |
xtick_at |
numeric vector with the locations of the x-axis tick marks |
line_col_list |
a list may contain
|
line_width |
numeric value for segment width, default is |
arrow_size |
numeric value for arrow size, default is |
no_enddate_extention |
numeric value for extending the arrow when end date is missing for |
marker_col_list |
a list may contain
|
marker_shape_list |
a list may contain
|
show_days_label |
boolean value for showing y-axis label, default is |
xlim |
numeric vector for x-axis limit, default is
|
xlab |
string to be shown as x-axis label, default is |
show_title |
boolean value for showing title of the plot, default is |
title |
string to be shown as title of the plot, default is |
plot object
Xuefeng Hou (houx14) [email protected]
Tina Cho (chot) [email protected]
Molly He (hey59) [email protected]
Ting Qi (qit3) [email protected]
library(dplyr) # ADSL ADSL <- osprey::rADSL %>% filter(USUBJID == rADSL$USUBJID[1]) %>% mutate( TRTSDT = as.Date(TRTSDTM), max_date = max(as.Date(LSTALVDT), as.Date(DTHDT), na.rm = TRUE), max_day = as.numeric(as.Date(max_date) - as.Date(TRTSDT)) + 1 ) %>% select(USUBJID, STUDYID, TRTSDT, max_day) # Example 1 Exposure "ADEX" ADEX <- osprey::rADEX %>% select(USUBJID, STUDYID, ASTDTM, PARCAT2, AVAL, AVALU, PARAMCD) ADEX <- left_join(ADSL, ADEX, by = c("USUBJID", "STUDYID")) ADEX <- ADEX %>% filter(PARAMCD == "DOSE") %>% arrange(PARCAT2, PARAMCD) %>% mutate(diff = c(0, diff(AVAL, lag = 1))) %>% mutate( Modification = case_when( diff < 0 ~ "Decrease", diff > 0 ~ "Increase", diff == 0 ~ "None" ) ) %>% mutate( ASTDT_dur = as.numeric( as.Date( substr(as.character(ASTDTM), 1, 10) ) - as.Date(TRTSDT) + 1 ) ) p1 <- patient_domain_profile( domain = "Exposure (ADEX)", var_names = ADEX$PARCAT2, marker_pos = ADEX$ASTDT_dur, arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADEX$Modification), marker_col_opt = c("Increase" = "red", "Decrease" = "green", "None" = "blue"), marker_col_legend = NULL ), marker_shape_list = list( marker_shape = factor(ADEX$Modification), marker_shape_opt = c("Increase" = 24, "Decrease" = 25, "None" = 23), marker_shape_legend = "Dose Modification" ), show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p1 # Example 2 Adverse Event "ADAE" # Note that ASTDY is represented by a circle and AENDY is represented by a square. # If AENDY and ASTDY occur on the same day only AENDY will be shown. # Adverse Event ADAE ADAE <- osprey::rADAE %>% select(USUBJID, STUDYID, AESOC, AEDECOD, AESER, AETOXGR, AEREL, ASTDY, AENDY) ADAE <- left_join(ADSL, ADAE, by = c("USUBJID", "STUDYID")) p2 <- patient_domain_profile( domain = "Adverse Event (ADAE)", var_names = ADAE$AEDECOD, marker_pos = ADAE[, c("ASTDY", "AENDY")], arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = list( line_col = ADAE$AESER, line_col_legend = "Serious", line_col_opt = c("blue", "green") ), line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADAE$AETOXGR), marker_col_opt = c("3" = "yellow", "4" = "red"), marker_col_legend = NULL ), marker_shape_list = list( marker_shape = NULL, marker_shape_opt = NULL, marker_shape_legend = "Grade" ), show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p2 # Example 3 Tumor Response "ADRS" ADRS <- osprey::rADRS %>% select(USUBJID, STUDYID, PARAMCD, PARAM, AVALC, AVAL, ADY, ADTM) ADRS <- left_join(ADSL, ADRS, by = c("USUBJID", "STUDYID")) p3 <- patient_domain_profile( domain = "Tumor Response (ADRS)", var_names = ADRS$PARAMCD, marker_pos = ADRS$ADY, arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADRS$AVALC), marker_col_opt = c( "CR" = "green", "PR" = "blue", "SD" = "yellow", "PD" = "red", "NE" = "pink", "Y" = "lightblue", "N" = "darkred" ), marker_col_legend = NULL ), marker_shape_list = list( marker_shape = factor(ADRS$AVALC), marker_shape_opt = c( "CR" = 21, "PR" = 24, "SD" = 23, "PD" = 22, "NE" = 14, "Y" = 11, "N" = 8 ), marker_shape_legend = "Response" ), show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p3 # Example 4 Concomitant Med "ADCM" ADCM <- osprey::rADCM %>% select(USUBJID, STUDYID, ASTDTM, AENDTM, CMDECOD, ASTDY, AENDY) ADCM <- left_join(ADSL, ADCM, by = c("USUBJID", "STUDYID")) p4 <- patient_domain_profile( domain = "Concomitant Med (ADCM)", var_names = ADCM$CMDECOD, marker_pos = ADCM[, c("ASTDY", "AENDY")], arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = list(line_col_opt = "orange"), line_width = 1, arrow_size = 0.1, no_enddate_extention = 50, marker_col_list = list(marker_col_opt = "orange"), marker_shape_list = NULL, show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p4 # Example 5 Laboratory "ADLB" ADLB <- osprey::rADLB %>% select( USUBJID, STUDYID, LBSEQ, PARAMCD, BASETYPE, ADTM, ADY, ATPTN, AVISITN, LBTESTCD, ANRIND ) ADLB <- left_join(ADSL, ADLB, by = c("USUBJID", "STUDYID")) ADLB <- ADLB %>% group_by(USUBJID) %>% mutate(ANRIND = factor(ANRIND, levels = c("LOW", "NORMAL", "HIGH"))) p5 <- patient_domain_profile( domain = "Laboratory (ADLB)", var_names = ADLB$LBTESTCD, marker_pos = ADLB$ADY, arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADLB$ANRIND), marker_col_opt = c( "HIGH" = "red", "LOW" = "blue", "NORMAL" = "green", "NA" = "green" ) ), marker_shape_list = list( marker_shape = factor(ADLB$ANRIND), marker_shape_opt = c( "HIGH" = 24, "LOW" = 25, "NORMAL" = 23, "NA" = 23 ), marker_shape_legend = "Labs Abnormality" ), show_days_label = TRUE, xlim = c(-30, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p5
library(dplyr) # ADSL ADSL <- osprey::rADSL %>% filter(USUBJID == rADSL$USUBJID[1]) %>% mutate( TRTSDT = as.Date(TRTSDTM), max_date = max(as.Date(LSTALVDT), as.Date(DTHDT), na.rm = TRUE), max_day = as.numeric(as.Date(max_date) - as.Date(TRTSDT)) + 1 ) %>% select(USUBJID, STUDYID, TRTSDT, max_day) # Example 1 Exposure "ADEX" ADEX <- osprey::rADEX %>% select(USUBJID, STUDYID, ASTDTM, PARCAT2, AVAL, AVALU, PARAMCD) ADEX <- left_join(ADSL, ADEX, by = c("USUBJID", "STUDYID")) ADEX <- ADEX %>% filter(PARAMCD == "DOSE") %>% arrange(PARCAT2, PARAMCD) %>% mutate(diff = c(0, diff(AVAL, lag = 1))) %>% mutate( Modification = case_when( diff < 0 ~ "Decrease", diff > 0 ~ "Increase", diff == 0 ~ "None" ) ) %>% mutate( ASTDT_dur = as.numeric( as.Date( substr(as.character(ASTDTM), 1, 10) ) - as.Date(TRTSDT) + 1 ) ) p1 <- patient_domain_profile( domain = "Exposure (ADEX)", var_names = ADEX$PARCAT2, marker_pos = ADEX$ASTDT_dur, arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADEX$Modification), marker_col_opt = c("Increase" = "red", "Decrease" = "green", "None" = "blue"), marker_col_legend = NULL ), marker_shape_list = list( marker_shape = factor(ADEX$Modification), marker_shape_opt = c("Increase" = 24, "Decrease" = 25, "None" = 23), marker_shape_legend = "Dose Modification" ), show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p1 # Example 2 Adverse Event "ADAE" # Note that ASTDY is represented by a circle and AENDY is represented by a square. # If AENDY and ASTDY occur on the same day only AENDY will be shown. # Adverse Event ADAE ADAE <- osprey::rADAE %>% select(USUBJID, STUDYID, AESOC, AEDECOD, AESER, AETOXGR, AEREL, ASTDY, AENDY) ADAE <- left_join(ADSL, ADAE, by = c("USUBJID", "STUDYID")) p2 <- patient_domain_profile( domain = "Adverse Event (ADAE)", var_names = ADAE$AEDECOD, marker_pos = ADAE[, c("ASTDY", "AENDY")], arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = list( line_col = ADAE$AESER, line_col_legend = "Serious", line_col_opt = c("blue", "green") ), line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADAE$AETOXGR), marker_col_opt = c("3" = "yellow", "4" = "red"), marker_col_legend = NULL ), marker_shape_list = list( marker_shape = NULL, marker_shape_opt = NULL, marker_shape_legend = "Grade" ), show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p2 # Example 3 Tumor Response "ADRS" ADRS <- osprey::rADRS %>% select(USUBJID, STUDYID, PARAMCD, PARAM, AVALC, AVAL, ADY, ADTM) ADRS <- left_join(ADSL, ADRS, by = c("USUBJID", "STUDYID")) p3 <- patient_domain_profile( domain = "Tumor Response (ADRS)", var_names = ADRS$PARAMCD, marker_pos = ADRS$ADY, arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADRS$AVALC), marker_col_opt = c( "CR" = "green", "PR" = "blue", "SD" = "yellow", "PD" = "red", "NE" = "pink", "Y" = "lightblue", "N" = "darkred" ), marker_col_legend = NULL ), marker_shape_list = list( marker_shape = factor(ADRS$AVALC), marker_shape_opt = c( "CR" = 21, "PR" = 24, "SD" = 23, "PD" = 22, "NE" = 14, "Y" = 11, "N" = 8 ), marker_shape_legend = "Response" ), show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p3 # Example 4 Concomitant Med "ADCM" ADCM <- osprey::rADCM %>% select(USUBJID, STUDYID, ASTDTM, AENDTM, CMDECOD, ASTDY, AENDY) ADCM <- left_join(ADSL, ADCM, by = c("USUBJID", "STUDYID")) p4 <- patient_domain_profile( domain = "Concomitant Med (ADCM)", var_names = ADCM$CMDECOD, marker_pos = ADCM[, c("ASTDY", "AENDY")], arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = list(line_col_opt = "orange"), line_width = 1, arrow_size = 0.1, no_enddate_extention = 50, marker_col_list = list(marker_col_opt = "orange"), marker_shape_list = NULL, show_days_label = TRUE, xlim = c(-28, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p4 # Example 5 Laboratory "ADLB" ADLB <- osprey::rADLB %>% select( USUBJID, STUDYID, LBSEQ, PARAMCD, BASETYPE, ADTM, ADY, ATPTN, AVISITN, LBTESTCD, ANRIND ) ADLB <- left_join(ADSL, ADLB, by = c("USUBJID", "STUDYID")) ADLB <- ADLB %>% group_by(USUBJID) %>% mutate(ANRIND = factor(ANRIND, levels = c("LOW", "NORMAL", "HIGH"))) p5 <- patient_domain_profile( domain = "Laboratory (ADLB)", var_names = ADLB$LBTESTCD, marker_pos = ADLB$ADY, arrow_end = ADSL$max_day, xtick_at = waiver(), line_col_list = NULL, line_width = 1, arrow_size = 0.1, no_enddate_extention = 0, marker_col_list = list( marker_col = factor(ADLB$ANRIND), marker_col_opt = c( "HIGH" = "red", "LOW" = "blue", "NORMAL" = "green", "NA" = "green" ) ), marker_shape_list = list( marker_shape = factor(ADLB$ANRIND), marker_shape_opt = c( "HIGH" = 24, "LOW" = 25, "NORMAL" = 23, "NA" = 23 ), marker_shape_legend = "Labs Abnormality" ), show_days_label = TRUE, xlim = c(-30, ADSL$max_day), xlab = "Study Day", title = paste("Patient Profile: ", ADSL$USUBJID) ) p5
Description of this plot
spiderplot_simple( anl, byvar = "USUBJID", days = "TRTDURD", mes_value = "PARAM", group_col = "USUBJID", baseday = 0 )
spiderplot_simple( anl, byvar = "USUBJID", days = "TRTDURD", mes_value = "PARAM", group_col = "USUBJID", baseday = 0 )
anl |
The analysis data frame |
byvar |
Analysis dataset |
days |
Variable with time in days |
mes_value |
Variable with measurement |
group_col |
Variable to color the individual lines and id in plot |
baseday |
Numeric Value, points with only smaller values will be cut out |
ggplot
object
Mika Maekinen
library(dplyr) library(nestcolor) ADSL <- osprey::rADSL[1:15, ] ADTR <- osprey::rADTR ANL <- left_join(ADSL, ADTR) ANL %>% dplyr::filter(ANL01FL == "Y" & PARAMCD == "SLDINV") %>% spiderplot_simple(group_col = "SEX", days = "ADY", mes_value = "AVAL")
library(dplyr) library(nestcolor) ADSL <- osprey::rADSL[1:15, ] ADTR <- osprey::rADTR ANL <- left_join(ADSL, ADTR) ANL %>% dplyr::filter(ANL01FL == "Y" & PARAMCD == "SLDINV") %>% spiderplot_simple(group_col = "SEX", days = "ADY", mes_value = "AVAL")
One of slref
or anl
need to be specified. The conversion from SAS
code in filters dataset may not work in all
cases. In case of failure a sensible error message should be returned.
stream_filter( slref = NULL, anl = NULL, filters, suffix, slref_keep = NULL, usubjid = "USUBJID" )
stream_filter( slref = NULL, anl = NULL, filters, suffix, slref_keep = NULL, usubjid = "USUBJID" )
slref |
The subject level data frame (typically |
anl |
The analysis data frame |
filters |
The name of the filters dataset |
suffix |
The suffix to apply in quotes (e.g. |
slref_keep |
Variables to keep from |
usubjid |
The unique subject identifier variable in quotes (e.g. |
dataframe
object
Iain Bennett
ADSL <- osprey::rADSL ADTTE <- osprey::rADTTE filters <- as.data.frame(rbind( c(ID = "IT", FLTTARGET = "SLREF", FLTWHERE = "where 1 eq 1"), c(ID = "BIO", FLTTARGET = "SLREF", FLTWHERE = "where BMRKR1 ge 4.3"), c(ID = "M", FLTTARGET = "SLREF", FLTWHERE = "where SEX eq 'M'"), c(ID = "PFS", FLTTARGET = "ANL", FLTWHERE = "where PARAMCD eq 'PFS'"), c(ID = "OS", FLTTARGET = "ANL", FLTWHERE = "where PARAMCD eq 'OS'") )) ANL <- stream_filter( slref = ADSL, anl = ADTTE, suffix = "IT_PFS_BIO", filters = filters )
ADSL <- osprey::rADSL ADTTE <- osprey::rADTTE filters <- as.data.frame(rbind( c(ID = "IT", FLTTARGET = "SLREF", FLTWHERE = "where 1 eq 1"), c(ID = "BIO", FLTTARGET = "SLREF", FLTWHERE = "where BMRKR1 ge 4.3"), c(ID = "M", FLTTARGET = "SLREF", FLTWHERE = "where SEX eq 'M'"), c(ID = "PFS", FLTTARGET = "ANL", FLTWHERE = "where PARAMCD eq 'PFS'"), c(ID = "OS", FLTTARGET = "ANL", FLTWHERE = "where PARAMCD eq 'OS'") )) ANL <- stream_filter( slref = ADSL, anl = ADTTE, suffix = "IT_PFS_BIO", filters = filters )
SAS
code to R codeWill convert following SAS
operators: eq, =, le, lt, ge, gt, index
Will convert following logic: and, or, ()
Will convert all unquoted values to upper case (assumed to be variable names)
All quoted values will be returned with single quotes - may fail if have quotes within quotes
stream_filter_convwhere(x)
stream_filter_convwhere(x)
x |
a character string of |
a character string of R code
Iain Bennett
stream_filter_convwhere(x = "where X in (1 2 3 4) and Y gt 4 ") stream_filter_convwhere(x = "where X = \"fred\" and Y gt 4 ")
stream_filter_convwhere(x = "where X in (1 2 3 4) and Y gt 4 ") stream_filter_convwhere(x = "where X = \"fred\" and Y gt 4 ")
SAS
for logic optionsAssumption is that use in filters is to only resolve true vs false
Primarily for use with stream_filter and related stream_filter_convwhere
functions
stream_filter_index(string1, string2)
stream_filter_index(string1, string2)
string1 |
The string to search within - can be a vector |
string2 |
The string to search for - must have length 1 |
boolean
indicator
Iain Bennett
AEACN <- c("DRUG MODIFIED", "DRUG STOPPED", "DOSE/DRUG MODIFIED") stream_filter_index(AEACN, "DRUG MODIFIED")
AEACN <- c("DRUG MODIFIED", "DRUG STOPPED", "DOSE/DRUG MODIFIED") stream_filter_index(AEACN, "DRUG MODIFIED")