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,
decorators = NULL
)
Arguments
- label
(
character(1)
) Label shown in the navigation item for the module or module group. Formodules()
defaults to"root"
. SeeDetails
.- x
(
data_extract_spec
orlist
of 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_spec
orlist
of multipledata_extract_spec
) Variable names selected to plot along the y-axis by default. Can be numeric, factor or character.- row_facet
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specification of the data variable(s) to use for faceting rows.- col_facet
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specification of the data variable(s) to use for faceting columns.- facet
(
logical
) optional, specifies whether the facet encodingsui
elements are toggled on and shown to the user by default. Defaults toTRUE
if eitherrow_facet
orcolumn_facet
are supplied.- color
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specification of the data variable(s) selected for the outline color inside the coloring settings. It will be applied whencolor_settings
is set toTRUE
.- fill
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specification of the data variable(s) selected for the fill color inside the coloring settings. It will be applied whencolor_settings
is set toTRUE
.- size
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specification of the data variable(s) selected for the size ofgeom_point
plots inside the coloring settings. It will be applied whencolor_settings
is 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 andUI
tool 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
, andmax
intended for use with a slider UI element.- plot_width
(
numeric
) optional, specifies the plot width as a three-element vector ofvalue
,min
, andmax
for 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,ggplot2
theme 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_args
and 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.- decorators
-
(
list
ofteal_transform_module
, namedlist
ofteal_transform_module
orNULL
) optional, if notNULL
, decorator for tables or plots included in the module. When a named list ofteal_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
tm_g_bivariate
" 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 tm_g_bivariate
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::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
#> Initializing reporter_previewer_module
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
#> Initializing reporter_previewer_module
if (interactive()) {
shinyApp(app$ui, app$server)
}