Module enables the creation of univariate and bivariate plots, facilitating the exploration of data distributions and relationships between two variables.
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"),
ggplot2_args = teal.widgets::ggplot2_args(),
pre_output = NULL,
post_output = NULL,
transformators = list(),
decorators = list()
)Arguments
- label
(
character(1)) Label shown in the navigation item for the module or module group. Formodules()defaults to"root". SeeDetails.- x
(
data_extract_specorlistof multipledata_extract_spec) Variable names selected to plot along the x-axis by default. Can be numeric, factor or character. No empty selections are allowed.- y
(
data_extract_specorlistof multipledata_extract_spec) Variable names selected to plot along the y-axis by default. Can be numeric, factor or character.- row_facet
(
data_extract_specorlistof multipledata_extract_spec) optional, specification of the data variable(s) to use for faceting rows.- col_facet
(
data_extract_specorlistof multipledata_extract_spec) optional, specification of the data variable(s) to use for faceting columns.- facet
(
logical) optional, specifies whether the facet encodingsuielements are toggled on and shown to the user by default. Defaults toTRUEif eitherrow_facetorcolumn_facetare supplied.- color
(
data_extract_specorlistof multipledata_extract_spec) optional, specification of the data variable(s) selected for the outline color inside the coloring settings. It will be applied whencolor_settingsis set toTRUE.- fill
(
data_extract_specorlistof multipledata_extract_spec) optional, specification of the data variable(s) selected for the fill color inside the coloring settings. It will be applied whencolor_settingsis set toTRUE.- size
(
data_extract_specorlistof multipledata_extract_spec) optional, specification of the data variable(s) selected for the size ofgeom_pointplots inside the coloring settings. It will be applied whencolor_settingsis set toTRUE.- use_density
(
logical) optional, indicates whether to plot density (TRUE) or frequency (FALSE). Defaults to frequency (FALSE).- color_settings
(
logical) Whether coloring, filling and size should be applied andUItool offered to the user.- free_x_scales
(
logical) optional, whether X scaling shall be changeable. Does not allow scaling to be changed by default (FALSE).- free_y_scales
(
logical) optional, whether Y scaling shall be changeable. Does not allow scaling to be changed by default (FALSE).- plot_height
(
numeric) optional, specifies the plot height as a three-element vector ofvalue,min, andmaxintended for use with a slider UI element.- plot_width
(
numeric) optional, specifies the plot width as a three-element vector ofvalue,min, andmaxfor a slider encoding the plot width.- rotate_xaxis_labels
(
logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).- swap_axes
(
logical) optional, whether to swap X and Y axes. Defaults toFALSE.- ggtheme
(
character) optional,ggplot2theme to be used by default. Defaults to"gray".- ggplot2_args
-
(
ggplot2_args) object created byteal.widgets::ggplot2_args()with settings for the module plot. The argument is merged with options variableteal.ggplot2_argsand default module setup.For more details see the vignette:
vignette("custom-ggplot2-arguments", package = "teal.widgets") - pre_output
(
shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.- post_output
(
shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements likeshiny::helpText()are useful.- transformators
(
listofteal_transform_module) that will be applied to transform module's data input. To learn more checkvignette("transform-input-data", package = "teal").- decorators
-
(named
listof lists ofteal_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.
Note
For more examples, please see the vignette "Using bivariate plot" via
vignette("using-bivariate-plot", package = "teal.modules.general").
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_bivariate(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied to the `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.modules.general").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
Examples
# general data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
CO2 <- data.frame(CO2)
})
app <- init(
data = data,
modules = tm_g_bivariate(
x = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "conc",
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "uptake",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "Type",
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]]),
selected = "Treatment",
fixed = FALSE
)
)
)
)
#> Initializing tm_g_bivariate
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]
app <- init(
data = data,
modules = tm_g_bivariate(
x = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]]),
selected = "AGE",
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]]),
selected = "SEX",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]]),
selected = "ARM",
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]]),
selected = "COUNTRY",
fixed = FALSE
)
)
)
)
#> Initializing tm_g_bivariate
if (interactive()) {
shinyApp(app$ui, app$server)
}