Skip to contents

This teal module renders the UI and calls the function that creates a spaghetti plot.

Usage

tm_g_gh_spaghettiplot(
  label,
  dataname,
  param_var,
  param,
  param_var_label = "PARAM",
  idvar,
  xaxis_var,
  yaxis_var,
  xaxis_var_level = NULL,
  filter_var = yaxis_var,
  trt_group,
  trt_group_level = NULL,
  group_stats = "NONE",
  man_color = NULL,
  color_comb = NULL,
  xtick = ggplot2::waiver(),
  xlabel = xtick,
  rotate_xlab = FALSE,
  facet_ncol = 2,
  free_x = FALSE,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  font_size = c(12, 8, 20),
  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,
  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 ADLB.

param_var

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

param

biomarker selected.

param_var_label

single name of variable in analysis data that includes parameter labels.

idvar

name of unique subject id variable.

xaxis_var

single name of variable in analysis data that is used as x-axis in the plot for the respective goshawk function.

yaxis_var

single name of variable in analysis data that is used as summary variable in the respective goshawk function.

xaxis_var_level

vector that can be used to define the factor level of xaxis_var. Only use it when xaxis_var is character or factor.

filter_var

data constraint variable.

trt_group

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

trt_group_level

vector that can be used to define factor level of trt_group.

group_stats

control group mean or median overlay.

man_color

string vector representing customized colors

color_comb

name or hex value for combined treatment color.

xtick

numeric vector to define the tick values of x-axis when x variable is numeric. Default value is waive().

xlabel

vector with same length of xtick to define the label of x-axis tick values. Default value is waive().

rotate_xlab

logical(1) value indicating whether to rotate x-axis labels

facet_ncol

numeric value indicating number of facets per row.

free_x

logical(1) should scales be "fixed" (FALSE) of "free" (TRUE) for x-axis in facet_wrap scales parameter.

plot_height

controls plot height.

plot_width

optional, controls plot width.

font_size

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

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.

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

shiny object

Author

Wenyi Liu (luiw2) wenyi.liu@roche.com

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

Examples


# Example using ADaM structure analysis dataset.

library(dplyr)

# 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 = 30,
    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(
    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 = 30,
                  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'
               ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
               ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')",
      vars = list(arm_mapping = arm_mapping)
    ),
    check = FALSE
  ),
  modules = teal::modules(
    teal.goshawk::tm_g_gh_spaghettiplot(
      label = "Spaghetti Plot",
      dataname = "ADLB",
      param_var = "PARAMCD",
      param = choices_selected(c("ALT", "CRP", "IGA"), "ALT"),
      idvar = "USUBJID",
      xaxis_var = choices_selected(c("Analysis Visit Code" = "AVISITCD"), "AVISITCD"),
      yaxis_var = choices_selected(c("AVAL", "CHG", "PCHG"), "AVAL"),
      filter_var = choices_selected(
        c("None" = "NONE", "Screening" = "BASE2", "Baseline" = "BASE"),
        "NONE"
      ),
      trt_group = choices_selected(c("ARM", "ACTARM"), "ARM"),
      color_comb = "#39ff14",
      man_color = c(
        "Combination" = "#000000",
        "Placebo" = "#fce300",
        "150mg QD" = "#5a2f5f"
      ),
      hline_arb = c(60, 50),
      hline_arb_color = c("grey", "red"),
      hline_arb_label = c("default A", "default B"),
      hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"),
      hline_vars_colors = c("pink", "brown", "purple", "black"),
    )
  )
)
#> [INFO] 2023-08-14 13:52:05.5119 pid:1122 token:[] teal.goshawk Initializing tm_g_gh_spaghettiplot
if (interactive()) {
  shinyApp(app$ui, app$server)
}