Skip to contents

This module produces a ggplot-style Kaplan-Meier plot for data with ADaM structure.

Usage

tm_g_km(
  label,
  dataname,
  parentname = ifelse(inherits(arm_var, "data_extract_spec"),
    teal.transform::datanames_input(arm_var), "ADSL"),
  arm_var,
  arm_ref_comp = NULL,
  paramcd,
  strata_var,
  facet_var,
  time_unit_var =
    teal.transform::choices_selected(teal.transform::variable_choices(dataname, "AVALU"),
    "AVALU", fixed = TRUE),
  aval_var = teal.transform::choices_selected(teal.transform::variable_choices(dataname,
    "AVAL"), "AVAL", fixed = TRUE),
  cnsr_var = teal.transform::choices_selected(teal.transform::variable_choices(dataname,
    "CNSR"), "CNSR", fixed = TRUE),
  conf_level = teal.transform::choices_selected(c(0.95, 0.9, 0.8), 0.95, keep_order =
    TRUE),
  font_size = c(11L, 1L, 30),
  control_annot_surv_med = control_surv_med_annot(),
  control_annot_coxph = control_coxph_annot(x = 0.27, y = 0.35, w = 0.3),
  legend_pos = c(0.9, 0.5),
  rel_height_plot = c(80L, 0L, 100L),
  plot_height = c(800L, 400L, 5000L),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  decorators = NULL
)

Arguments

label

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

dataname

(character)
analysis data used in teal module.

parentname

(character)
parent analysis data used in teal module, usually this refers to ADSL.

arm_var

(teal.transform::choices_selected())
object with all available choices and preselected option for variable names that can be used as arm_var. It defines the grouping variable in the results table.

arm_ref_comp

(list) optional,
if specified it must be a named list with each element corresponding to an arm variable in ADSL and the element must be another list (possibly with delayed teal.transform::variable_choices() or delayed teal.transform::value_choices() with the elements named ref and comp that the defined the default reference and comparison arms when the arm variable is changed.

paramcd

(teal.transform::choices_selected())
object with all available choices and preselected option for the parameter code variable from dataname.

strata_var

(teal.transform::choices_selected())
names of the variables for stratified analysis.

facet_var

(teal.transform::choices_selected())
object with all available choices and preselected option for names of variable that can be used for plot faceting.

time_unit_var

(teal.transform::choices_selected())
object with all available choices and pre-selected option for the time unit variable.

aval_var

(teal.transform::choices_selected())
object with all available choices and pre-selected option for the analysis variable.

cnsr_var

(teal.transform::choices_selected())
object with all available choices and preselected option for the censoring variable.

conf_level

(teal.transform::choices_selected())
object with all available choices and pre-selected option for the confidence level, each within range of (0, 1).

font_size

(numeric)
numeric vector of length 3 of current, minimum and maximum font size values.

control_annot_surv_med

(list)
parameters to control the position and size of the annotation table added to the plot when annot_surv_med = TRUE, specified using the control_surv_med_annot() function. Parameter options are: x, y, w, h, and fill. See control_surv_med_annot() for details.

control_annot_coxph

(list)
parameters to control the position and size of the annotation table added to the plot when annot_coxph = TRUE, specified using the control_coxph_annot() function. Parameter options are: x, y, w, h, fill, and ref_lbls. See control_coxph_annot() for details.

legend_pos

(numeric(2) or NULL)
vector containing x- and y-coordinates, respectively, for the legend position relative to the KM plot area. If NULL (default), the legend is positioned in the bottom right corner of the plot, or the middle right of the plot if needed to prevent overlapping.

rel_height_plot

(proportion)
proportion of total figure height to allocate to the Kaplan-Meier plot. Relative height of patients at risk table is then 1 - rel_height_plot. If annot_at_risk = FALSE or as_list = TRUE, this parameter is ignored.

plot_height

(numeric) optional
vector of length three with c(value, min, max). Specifies the height of the main plot and renders a slider on the plot to interactively adjust the plot height.

plot_width

(numeric) optional
vector of length three with c(value, min, max). Specifies the width of the main plot and renders a slider on the plot to interactively adjust the plot width.

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.

decorators

[Experimental] " (list of teal_transform_module, named list of teal_transform_module or" NULL) optional, if not NULL, decorator for tables or plots included in the module. When a named list of teal_transform_module, the decorators are applied to the respective output objects.

Otherwise, the decorators are applied to all objects, which is equivalent as using the name default.

See section "Decorating Module" below for more details.

Value

a teal_module object.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

  • plot (ggplot2)

For additional details and examples of decorators, refer to the vignette vignette("decorate-modules-output", package = "teal") or the teal_transform_module() documentation.

See also

The TLG Catalog where additional example apps implementing this module can be found.

Examples in Shinylive

example-1

Open in Shinylive

Examples

library(nestcolor)

data <- teal_data()
data <- within(data, {
  ADSL <- tmc_ex_adsl
  ADTTE <- tmc_ex_adtte
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

ADSL <- data[["ADSL"]]
ADTTE <- data[["ADTTE"]]

arm_ref_comp <- list(
  ACTARMCD = list(
    ref = "ARM B",
    comp = c("ARM A", "ARM C")
  ),
  ARM = list(
    ref = "B: Placebo",
    comp = c("A: Drug X", "C: Combination")
  )
)

app <- init(
  data = data,
  modules = modules(
    tm_g_km(
      label = "Kaplan-Meier Plot",
      dataname = "ADTTE",
      arm_var = choices_selected(
        variable_choices(ADSL, c("ARM", "ARMCD", "ACTARMCD")),
        "ARM"
      ),
      paramcd = choices_selected(
        value_choices(ADTTE, "PARAMCD", "PARAM"),
        "OS"
      ),
      arm_ref_comp = arm_ref_comp,
      strata_var = choices_selected(
        variable_choices(ADSL, c("SEX", "BMRKR2")),
        "SEX"
      ),
      facet_var = choices_selected(
        variable_choices(ADSL, c("SEX", "BMRKR2")),
        NULL
      )
    )
  )
)
#> Initializing tm_g_km
#> Initializing reporter_previewer_module
if (interactive()) {
  shinyApp(app$ui, app$server)
}