Skip to contents

Display butterfly plot as a shiny module

Usage

tm_g_butterfly(
  label,
  dataname,
  filter_var = NULL,
  right_var,
  left_var,
  category_var,
  color_by_var,
  count_by_var,
  facet_var = NULL,
  sort_by_var = teal.widgets::choices_selected(selected = "count", choices = c("count",
    "alphabetical")),
  legend_on = TRUE,
  plot_height = c(600L, 200L, 2000L),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL
)

Arguments

label

(character(1))
menu item label of the module in the teal app.

dataname

(character(1))
analysis data used in the teal module, needs to be available in the list passed to the data argument of teal::init().

filter_var

(choices_selected) variable name of data filter, please see details regarding expected values, default is NULL. choices vector with filter_var choices, default is NULL

right_var

(choices_selected) dichotomization variable for right side

left_var

(choices_selected) dichotomization variable for left side

category_var

(choices_selected) category (y axis) variable

color_by_var

(choices_selected) variable defines color blocks within each bar

count_by_var

(choices_selected) variable defines how x axis is calculated

facet_var

(choices_selected) variable for row facets

sort_by_var

(choices_selected) argument for order of class and term elements in table, default here is "count"

legend_on

(boolean) value for whether legend is displayed

plot_height

(numeric(3))
vector to indicate default value, minimum and maximum values.

plot_width

(numeric(3))
vector to indicate default value, minimum and maximum values.

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

the teal::module() object.

Details

filter_var option is designed to work in conjunction with filtering function provided by teal (encoding panel on the right hand side of the shiny app). It can be used as quick access to predefined subsets of the domain datasets (not subject-level dataset) to be used for analysis, denoted by an value of "Y". Each variable within the filter_var_choices is expected to contain values of either "Y" or "N". If multiple variables are selected as filter_var, only observations with "Y" value in each and every selected variables will be used for subsequent analysis. Flag variables (from ADaM datasets) can be used directly as filter.

Author

Carolyn Zhang (zhanc107) carolyn.zhang@duke.edu

Chendi Liao (liaoc10) chendi.liao@roche.com

Examples


# Example using stream (ADaM) dataset
library(dplyr)
library(scda)

set.seed(23)
ADSL <- synthetic_cdisc_data("latest")$adsl
ADAE <- synthetic_cdisc_data("latest")$adae
ADSL <- mutate(ADSL, DOSE = paste(sample(1:3, n(), replace = TRUE), "UG"))
ADAE <- mutate(
  ADAE,
  flag1 = ifelse(AETOXGR == 1, 1, 0),
  flag2 = ifelse(AETOXGR == 2, 1, 0),
  flag3 = ifelse(AETOXGR == 3, 1, 0),
  flag1_filt = rep("Y", n())
)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", ADSL,
      code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl
              set.seed(23)
              ADSL <- mutate(ADSL, DOSE = paste(sample(1:3, n(), replace = TRUE), 'UG'))"
    ),
    cdisc_dataset("ADAE", ADAE,
      code = "ADAE <- synthetic_cdisc_data(\"latest\")$adae
              ADAE <- mutate(ADAE,
              flag1 = ifelse(AETOXGR == 1, 1, 0),
              flag2 = ifelse(AETOXGR == 2, 1, 0),
              flag3 = ifelse(AETOXGR == 3, 1, 0),
              flag1_filt = rep('Y', n()))"
    ),
    check = TRUE
  ),
  modules = modules(
    tm_g_butterfly(
      label = "Butterfly Plot",
      dataname = "ADAE",
      right_var = choices_selected(
        selected = "SEX",
        choices = c("DOSE", "SEX", "ARM", "RACE", "flag1", "flag2", "flag3")
      ),
      left_var = choices_selected(
        selected = "RACE",
        choices = c("DOSE", "SEX", "ARM", "RACE", "flag1", "flag2", "flag3")
      ),
      category_var = choices_selected(selected = "AEBODSYS", choices = c("AEDECOD", "AEBODSYS")),
      color_by_var = choices_selected(selected = "AETOXGR", choices = c("AETOXGR", "None")),
      count_by_var = choices_selected(
        selected = "# of patients",
        choices = c("# of patients", "# of AEs")
      ),
      facet_var = choices_selected(selected = NULL, choices = c("RACE", "SEX", "ARM")),
      sort_by_var = choices_selected(selected = "count", choices = c("count", "alphabetical")),
      legend_on = TRUE,
      plot_height = c(600, 200, 2000)
    )
  )
)
#> [INFO] 2022-06-17 09:55:58.9451 pid:1163 token:[] teal.osprey Initializing tm_g_butterfly
if (FALSE) {
shinyApp(app$ui, app$server)
}