Skip to contents

Univariate and bivariate visualizations

Usage

tm_g_bivariate(
  label = "Bivariate Plots",
  x,
  y,
  row_facet = NULL,
  col_facet = NULL,
  facet = !is.null(row_facet) || !is.null(col_facet),
  color = NULL,
  fill = NULL,
  size = NULL,
  use_density = FALSE,
  color_settings = FALSE,
  free_x_scales = FALSE,
  free_y_scales = FALSE,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  rotate_xaxis_labels = FALSE,
  swap_axes = FALSE,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void",
    "test"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  pre_output = NULL,
  post_output = NULL
)

Arguments

label

(character) Label shown in the navigation item for the module.

x

(data_extract_spec or list of multiple data_extract_spec) Variable names selected to plot along the x-axis by default. Variable can be numeric, factor or character. No empty selections are allowed!

y

(data_extract_spec or list of multiple data_extract_spec) Variable names selected to plot along the y-axis by default. Variable can be numeric, factor or character.

row_facet

optional, (data_extract_spec or list of multiple data_extract_spec) Variables for row facetting.

col_facet

optional, (data_extract_spec or list of multiple data_extract_spec) Variables for col facetting.

facet

optional, (logical) to specify whether the facet encodings ui elements are toggled on and shown to the user by default. Defaults to TRUE if either row_facet or column_facet are supplied.

color

optional, (data_extract_spec or list of multiple data_extract_spec) Variables selected for the outline color inside the coloring settings. It will be applied when color_settings is set to TRUE.

fill

optional, (data_extract_spec or list of multiple data_extract_spec) Variables selected for the fill color inside the coloring settings. It will be applied when color_settings is set to TRUE.

size

optional, (data_extract_spec or list of multiple data_extract_spec) Variables selected for the size of geom_point plots inside the coloring settings. It will be applied when color_settings is set to TRUE.

use_density

optional, (logical) value for whether density (TRUE) is plotted or frequency (FALSE). Defaults to frequency (FALSE).

color_settings

(logical) Whether coloring, filling and size should be applied and UI tool offered to the user.

free_x_scales

optional, (logical) Whether X scaling shall be changeable. Does not allow scaling to be changed by default (FALSE).

free_y_scales

optional, (logical) Whether Y scaling shall be changeable. Does not allow scaling to be changed by default (FALSE).

plot_height

optional, (numeric) A vector of length three with c(value, min and max) for a slider encoding the plot height.

plot_width

optional, (numeric) A vector of length three with c(value, min and max) for a slider encoding the plot width.

rotate_xaxis_labels

optional, (logical) Whether to rotate plot X axis labels. Does not rotate by default (FALSE).

swap_axes

optional, (logical) Whether to swap X and Y axes. Defaults to FALSE.

ggtheme

optional, (character) ggplot2 theme to be used by default. One of c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void", "test"). Each theme can be chosen by the user during the session. Defaults to "gray".

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

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.

Details

This is a general module to visualize 1 & 2 dimensional data.

Note

For more examples, please see the vignette "Using bivariate plot" via vignette("using-bivariate-plot", package = "teal.modules.general").

Examples

# Bivariate plot of selected variable (AGE) against selected (SEX)
library(scda)
ADSL <- synthetic_cdisc_data("latest")$adsl

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", ADSL, code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"),
    check = TRUE
  ),
  modules = modules(
    tm_g_bivariate(
      x = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(ADSL),
          selected = "AGE",
          fixed = FALSE
        )
      ),
      y = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(ADSL),
          selected = "SEX",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      ggplot2_args = teal.widgets::ggplot2_args(labs = list(subtitle = "Plot generated by Bivariate Module"))
    )
  )
)
#> [INFO] 2022-06-14 17:42:31.7855 pid:1110 token:[] teal.modules.general Initializing tm_g_bivariate
if (FALSE) {
shinyApp(app$ui, app$server)
}