Skip to contents

This teal module renders the UI and calls the functions that create a box plot and accompanying summary table.

Usage

tm_g_gh_boxplot(
  label,
  dataname,
  param_var,
  param,
  yaxis_var = teal.transform::choices_selected(c("AVAL", "CHG"), "AVAL"),
  xaxis_var = teal.transform::choices_selected("AVISITCD", "AVISITCD"),
  facet_var = teal.transform::choices_selected(c("ARM", "ACTARM"), "ARM"),
  trt_group,
  color_manual = NULL,
  shape_manual = NULL,
  facet_ncol = NULL,
  loq_legend = TRUE,
  rotate_xlab = FALSE,
  hline_arb = numeric(0),
  hline_arb_color = "red",
  hline_arb_label = "Horizontal line",
  hline_vars = character(0),
  hline_vars_colors = "green",
  hline_vars_labels = hline_vars,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  font_size = c(12, 8, 20),
  dot_size = c(2, 1, 12),
  alpha = c(0.8, 0, 1),
  pre_output = NULL,
  post_output = NULL
)

Arguments

label

menu item label of the module in the teal app.

dataname

analysis data passed to the data argument of init. E.g. ADaM structured laboratory data frame ALB.

param_var

name of variable containing biomarker codes e.g. PARAMCD.

param

list of biomarkers of interest.

yaxis_var

name of variable containing biomarker results displayed on y-axis e.g. AVAL. When not provided, it defaults to choices_selected(c("AVAL", "CHG"), "AVAL").

xaxis_var

variable to categorize the x-axis. When not provided, it defaults to choices_selected("AVISITCD", "AVISITCD").

facet_var

variable to facet the plots by. When not provided, it defaults to choices_selected(c("ARM", "ACTARM"), "ARM").

trt_group

choices_selected object with available choices and pre-selected option for variable names representing treatment group e.g. ARM.

color_manual

vector of colors applied to treatment values.

shape_manual

vector of symbols applied to LOQ values.

facet_ncol

numeric value indicating number of facets per row.

loq_legend

loq legend toggle.

rotate_xlab

45 degree rotation of x-axis values.

hline_arb

numeric vector of at most 2 values identifying intercepts for arbitrary horizontal lines.

hline_arb_color

a character vector of at most length of hline_arb. naming the color for the arbitrary horizontal lines.

hline_arb_label

a character vector of at most length of hline_arb. naming the label for the arbitrary horizontal lines.

hline_vars

a character vector to name the columns that will define additional horizontal lines.

hline_vars_colors

a character vector naming the colors for the additional horizontal lines.

hline_vars_labels

a character vector naming the labels for the additional horizontal lines that will appear in the legend.

plot_height

controls plot height.

plot_width

optional, controls plot width.

font_size

font size control for title, x-axis label, y-axis label and legend.

dot_size

plot dot size.

alpha

numeric vector to define transparency of plotted points.

pre_output

(shiny.tag, optional)
with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag, optional) with text placed after the output to put the output into context. For example the shiny::helpText() elements are useful.

Value

an module object

Author

Jeff Tomlinson (tomlinsj) jeffrey.tomlinson@roche.com

Balazs Toth (tothb2) toth.balazs@gene.com

Examples


# Example using ADaM structure analysis dataset.

library(dplyr)
library(nestcolor)

# original ARM value = dose value
arm_mapping <- list(
  "A: Drug X" = "150mg QD",
  "B: Placebo" = "Placebo",
  "C: Combination" = "Combination"
)

set.seed(1)
ADSL <- goshawk::rADSL
ADLB <- goshawk::rADLB
var_labels <- lapply(ADLB, function(x) attributes(x)$label)
ADLB <- ADLB %>%
  dplyr::mutate(
    AVISITCD = dplyr::case_when(
      AVISIT == "SCREENING" ~ "SCR",
      AVISIT == "BASELINE" ~ "BL",
      grepl("WEEK", AVISIT) ~ paste("W", stringr::str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")),
      TRUE ~ as.character(NA)
    ),
    AVISITCDN = dplyr::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 = dplyr::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),
    ANRLO = 50,
    ANRHI = 75
  ) %>%
  dplyr::rowwise() %>%
  dplyr::group_by(PARAMCD) %>%
  dplyr::mutate(LBSTRESC = ifelse(
    USUBJID %in% sample(USUBJID, 1, replace = TRUE),
    paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC
  )) %>%
  dplyr::mutate(LBSTRESC = ifelse(
    USUBJID %in% sample(USUBJID, 1, replace = TRUE),
    paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC
  )) %>%
  ungroup()

attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]]
attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"
attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"

# add LLOQ and ULOQ variables
ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
ADLB <- dplyr::left_join(ADLB, ALB_LOQS, by = "PARAM")

app <- teal::init(
  data = teal.data::cdisc_data(
    adsl <- teal.data::cdisc_dataset("ADSL", ADSL, code = "ADSL <- goshawk::rADSL"),
    teal.data::cdisc_dataset(
      "ADLB",
      ADLB,
      code = "
        set.seed(1)
        ADLB <- goshawk::rADLB
        var_labels <- lapply(ADLB, function(x) attributes(x)$label)
        ADLB <- ADLB %>%
          dplyr::mutate(AVISITCD = dplyr::case_when(
            AVISIT == 'SCREENING' ~ 'SCR',
            AVISIT == 'BASELINE' ~ 'BL',
            grepl('WEEK', AVISIT) ~ paste('W', stringr::str_extract(AVISIT, '(?<=(WEEK ))[0-9]+')),
            TRUE ~ as.character(NA)),
            AVISITCDN = dplyr::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 = dplyr::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),
            ANRLO = 50,
            ANRHI = 75) %>%
          dplyr::rowwise() %>%
          dplyr::group_by(PARAMCD) %>%
          dplyr::mutate(LBSTRESC = ifelse(
            USUBJID %in% sample(USUBJID, 1, replace = TRUE),
            paste('<', round(runif(1, min = 25, max = 30))), LBSTRESC)) %>%
          dplyr::mutate(LBSTRESC = ifelse(
            USUBJID %in% sample(USUBJID, 1, replace = TRUE),
            paste( '>', round(runif(1, min = 70, max = 75))), LBSTRESC)) %>%
          ungroup()
        attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']]
        attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]
        attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit'
        attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit'
        # add LLOQ and ULOQ variables
        ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
        ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')",
      vars = list(ADSL = adsl, arm_mapping = arm_mapping)
    ),
    check = FALSE # to shorten the example check = FALSE, in real scenarios use check = TRUE
  ),
  modules = teal::modules(
    teal.goshawk::tm_g_gh_boxplot(
      label = "Box Plot",
      dataname = "ADLB",
      param_var = "PARAMCD",
      param = choices_selected(c("ALT", "CRP", "IGA"), "ALT"),
      yaxis_var = choices_selected(c("AVAL", "BASE", "CHG"), "AVAL"),
      xaxis_var = choices_selected(c("ACTARM", "ARM", "AVISITCD", "STUDYID"), "ARM"),
      facet_var = choices_selected(c("ACTARM", "ARM", "AVISITCD", "SEX"), "AVISITCD"),
      trt_group = choices_selected(c("ARM", "ACTARM"), "ARM"),
      loq_legend = TRUE,
      rotate_xlab = FALSE,
      hline_arb = c(60, 55),
      hline_arb_color = c("grey", "red"),
      hline_arb_label = c("default_hori_A", "default_hori_B"),
      hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"),
      hline_vars_colors = c("pink", "brown", "purple", "black"),
    )
  )
)
#> [INFO] 2023-08-14 13:51:57.9683 pid:1122 token:[] teal.goshawk Initializing tm_g_gh_boxplot
if (interactive()) {
  shinyApp(app$ui, app$server)
}