Skip to contents

This module produces a ggplot2::ggplot() type bar chart and summary table of counts per category.

Usage

tm_g_barchart_simple(
  x = NULL,
  fill = NULL,
  x_facet = NULL,
  y_facet = NULL,
  label = "Count Barchart",
  plot_options = NULL,
  plot_height = c(600L, 200L, 2000L),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  ggplot2_args = teal.widgets::ggplot2_args(),
  transformators = list(),
  decorators = list()
)

# Default S3 method
tm_g_barchart_simple(
  x = NULL,
  fill = NULL,
  x_facet = NULL,
  y_facet = NULL,
  label = "Count Barchart",
  plot_options = NULL,
  plot_height = c(600L, 200L, 2000L),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  ggplot2_args = teal.widgets::ggplot2_args(),
  transformators = list(),
  decorators = list()
)

# S3 method for class 'picks'
tm_g_barchart_simple(
  x = NULL,
  fill = NULL,
  x_facet = NULL,
  y_facet = NULL,
  label = "Count Barchart",
  plot_options = NULL,
  plot_height = c(600L, 200L, 2000L),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  ggplot2_args = teal.widgets::ggplot2_args(),
  transformators = list(),
  decorators = list()
)

Arguments

x

(picks, data_extract_spec, or list of data_extract_spec)
variable on the x-axis (required).

fill

(NULL, picks, data_extract_spec, or list thereof)
grouping variable for bar colors.

x_facet

(NULL, picks, data_extract_spec, or list thereof)
column-wise faceting groups.

y_facet

(NULL, picks, data_extract_spec, or list thereof)
row-wise faceting groups.

label

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

plot_options

(list)
list of plot options.

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.

ggplot2_args

(ggplot2_args) optional
object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with option teal.ggplot2_args and with default module arguments (hard coded in the module body). For more details, see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

a teal_module object.

Details

Categories can be defined up to four levels deep through x, fill, x_facet, and y_facet. The x encoding is always required; fill, x_facet, and y_facet may be NULL to omit them.

S3 dispatch uses the class of x: tm_g_barchart_simple.default() for teal.transform::data_extract_spec() (or list thereof) and tm_g_barchart_simple.picks() for teal.picks::picks(). Do not mix data_extract_spec and picks encodings in one call.

Methods (by class)

Decorating Module

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

  • plot (ggplot)

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_barchart_simple(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied only to `plot` output
   )
)

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

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Reporting

This module returns an object of class teal_module, that contains a server function. Since the server function returns a teal_report object, this makes this module reportable, which means that the reporting functionality will be turned on automatically by the teal framework.

For more information on reporting in teal, see the vignettes:

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, {
  library(teal.modules.clinical)
  library(formatters)
  library(dplyr)
  ADSL <- tmc_ex_adsl %>%
    mutate(ITTFL = factor("Y") %>%
      with_label("Intent-To-Treat Population Flag"))
  ADAE <- tmc_ex_adae %>%
    filter(!((AETOXGR == 1) & (AESEV == "MILD") & (ARM == "A: Drug X")))
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

ADSL <- data[["ADSL"]]
ADAE <- data[["ADAE"]]

app <- init(
  data = data,
  modules = modules(
    tm_g_barchart_simple(
      label = "ADAE Analysis",
      x = picks(
        datasets("ADSL"),
        variables(
          choices = c(
            "ARM", "ACTARM", "SEX",
            "RACE", "ITTFL", "SAFFL", "STRATA2"
          ),
          selected = "ACTARM",
          multiple = FALSE
        )
      ),
      fill = picks(
        datasets(choices = c("ADSL", "ADAE")),
        variables(
          choices = c(
            "ARM", "ACTARM", "SEX",
            "RACE", "ITTFL", "SAFFL", "STRATA2",
            "AETOXGR", "AESEV", "AESER"
          ),
          selected = "SEX",
          multiple = FALSE
        )
      ),
      x_facet = picks(
        datasets(choices = c("ADAE", "ADSL")),
        variables(
          choices = c(
            "AETOXGR", "AESEV", "AESER",
            "ARM", "ACTARM", "SEX",
            "RACE", "ITTFL", "SAFFL", "STRATA2"
          ),
          selected = "AETOXGR",
          multiple = FALSE
        )
      ),
      y_facet = picks(
        datasets(choices = c("ADAE", "ADSL")),
        variables(
          choices = c(
            "AETOXGR", "AESEV", "AESER",
            "ARM", "ACTARM", "SEX",
            "RACE", "ITTFL", "SAFFL", "STRATA2"
          ),
          selected = "AESEV",
          multiple = FALSE
        )
      )
    )
  )
)
#> Warning: variables has eager choices (character) while datasets has dynamic choices. It is not guaranteed that explicitly defined choices will be a subset of data selected in a previous element.
#> Warning: variables has eager choices (character) while datasets has dynamic choices. It is not guaranteed that explicitly defined choices will be a subset of data selected in a previous element.
#> Warning: variables has eager choices (character) while datasets has dynamic choices. It is not guaranteed that explicitly defined choices will be a subset of data selected in a previous element.
#> Warning: variables has eager choices (character) while datasets has dynamic choices. It is not guaranteed that explicitly defined choices will be a subset of data selected in a previous element.
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# Legacy `teal.transform::data_extract_spec()` encodings (default S3 method):
if (FALSE) { # \dontrun{
data <- teal_data()
data <- within(data, {
  library(dplyr)
  ADSL <- tmc_ex_adsl %>%
    mutate(ITTFL = factor("Y") %>% with_label("Intent-To-Treat Population Flag"))
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_g_barchart_simple(
      x = teal.transform::data_extract_spec(
        dataname = "ADSL",
        select = teal.transform::select_spec(
          choices = teal.transform::variable_choices("ADSL", c("ARM", "SEX")),
          selected = "ARM",
          multiple = FALSE
        )
      )
    )
  )
)
shiny::shinyApp(app$ui, app$server)
} # }