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 = teal.picks::picks(teal.picks::datasets(), teal.picks::variables(choices =
is.numeric | teal.picks::is_categorical(min.len = 2, max.len = 10), selected = 1L),
teal.picks::values()),
y,
row_facet,
col_facet,
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
(
picks) Variable specification for the x-axis. Created usingteal.picks::picks(). Can be numeric, factor or character. No empty selections are allowed.- y
(
picks) Variable specification for the y-axis. Created usingteal.picks::picks(). Can be numeric, factor or character.- row_facet
(
picks) optional, specification of the data variable(s) to use for faceting rows. Created usingteal.picks::picks().- col_facet
(
picks) optional, specification of the data variable(s) to use for faceting columns. Created usingteal.picks::picks().- 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
(
picks) optional, specification of the data variable(s) selected for the outline color inside the coloring settings. It will be applied whencolor_settingsis set toTRUE. Created usingteal.picks::picks().- fill
(
picks) optional, specification of the data variable(s) selected for the fill color inside the coloring settings. It will be applied whencolor_settingsis set toTRUE. Created usingteal.picks::picks().- size
(
picks) 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. Created usingteal.picks::picks().- 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.
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.
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:
vignette("reportable-shiny-application", package = "teal.reporter")vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Examples
# general data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
CO2 <- data.frame(CO2)
})
app <- init(
data = data,
modules = tm_g_bivariate(
label = "Bivariate Plots",
x = teal.picks::picks(
datasets("CO2"),
teal.picks::variables(selected = "conc")
),
y = teal.picks::picks(
datasets("CO2"),
teal.picks::variables(selected = "uptake")
),
row_facet = teal.picks::picks(
datasets("CO2"),
teal.picks::variables(selected = "Type")
),
col_facet = teal.picks::picks(
datasets("CO2"),
teal.picks::variables(selected = "Treatment")
)
)
)
#> Warning: teal.picks::variables(selected = "conc")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
#> Initializing tm_g_bivariate
#> Warning: teal.picks::variables(selected = "uptake")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
#> Warning: teal.picks::variables(selected = "Type")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
#> Warning: teal.picks::variables(selected = "Treatment")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
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(
label = "Bivariate Plots",
x = teal.picks::picks(
datasets("ADSL"),
teal.picks::variables(selected = "AGE")
),
y = teal.picks::picks(
datasets("ADSL"),
teal.picks::variables(selected = "SEX")
),
row_facet = teal.picks::picks(
datasets("ADSL"),
teal.picks::variables(selected = "ARM")
),
col_facet = teal.picks::picks(
datasets("ADSL"),
teal.picks::variables(selected = "COUNTRY")
)
)
)
#> Warning: teal.picks::variables(selected = "AGE")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
#> Initializing tm_g_bivariate
#> Warning: teal.picks::variables(selected = "SEX")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
#> Warning: teal.picks::variables(selected = "ARM")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
#> Warning: teal.picks::variables(selected = "COUNTRY")
#> - Setting explicit `selected` while `choices` are delayed (set using `tidyselect`) doesn't guarantee that `selected` is a subset of `choices`.
if (interactive()) {
shinyApp(app$ui, app$server)
}