Generates a customizable scatterplot using ggplot2
.
This module allows users to select variables for the x and y axes,
color and size encodings, faceting options, and more. It supports log transformations,
trend line additions, and dynamic adjustments of point opacity and size through UI controls.
Usage
tm_g_scatterplot(
label = "Scatterplot",
x,
y,
color_by = NULL,
size_by = NULL,
row_facet = NULL,
col_facet = NULL,
plot_height = c(600, 200, 2000),
plot_width = NULL,
alpha = c(1, 0, 1),
shape = shape_names,
size = c(5, 1, 15),
max_deg = 5L,
rotate_xaxis_labels = FALSE,
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
pre_output = NULL,
post_output = NULL,
table_dec = 4,
ggplot2_args = teal.widgets::ggplot2_args(),
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_spec
orlist
of multipledata_extract_spec
) Specifies variable names selected to plot along the x-axis by default.- y
(
data_extract_spec
orlist
of multipledata_extract_spec
) Specifies variable names selected to plot along the y-axis by default.- color_by
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, defines the color encoding. IfNULL
then no color encoding option will be displayed.- size_by
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, defines the point size encoding. IfNULL
then no size encoding option will be displayed.- row_facet
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specifies the variable(s) for faceting rows.- col_facet
(
data_extract_spec
orlist
of multipledata_extract_spec
) optional, specifies the variable(s) for faceting columns.- 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.- alpha
-
(
integer(1)
orinteger(3)
) optional, specifies point opacity.When the length of
alpha
is one: the plot points will have a fixed opacity.When the length of
alpha
is three: the plot points opacity are dynamically adjusted based on vector ofvalue
,min
, andmax
.
- shape
(
character
) optional, character vector with the names of the shape, e.g.c("triangle", "square", "circle")
. It defaults toshape_names
. This is a complete list fromvignette("ggplot2-specs", package="ggplot2")
.- size
-
(
integer(1)
orinteger(3)
) optional, specifies point size.When the length of
size
is one: the plot point sizes will have a fixed size.When the length of
size
is three: the plot points size are dynamically adjusted based on vector ofvalue
,min
, andmax
.
- max_deg
(
integer
) optional, maximum degree for the polynomial trend line. Must not be less than 1.- rotate_xaxis_labels
(
logical
) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE
).- ggtheme
(
character
) optional,ggplot2
theme to be used by default. Defaults to"gray"
.- 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.- table_dec
(
integer
) optional, number of decimal places used to round numeric values in the table.- 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")
- transformators
(
list
ofteal_transform_module
) that will be applied to transform module's data input. To learn more checkvignette("data-transform-as-shiny-module", package = "teal")
.- decorators
-
(
list
ofteal_transform_module
, namedlist
ofteal_transform_module
) optional, decorator for tables or plots included in the module output reported. 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 Module" below for more details.
Note
For more examples, please see the vignette "Using scatterplot" via
vignette("using-scatterplot", package = "teal.modules.general")
.
Decorating Module
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 <- CO2
})
app <- init(
data = data,
modules = modules(
tm_g_scatterplot(
label = "Scatterplot Choices",
x = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
selected = "conc",
multiple = FALSE,
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
selected = "uptake",
multiple = FALSE,
fixed = FALSE
)
),
color_by = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(
data[["CO2"]],
c("Plant", "Type", "Treatment", "conc", "uptake")
),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
size_by = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
selected = "uptake",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
)
)
)
)
#> Initializing tm_g_scatterplot
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 = modules(
tm_g_scatterplot(
label = "Scatterplot Choices",
x = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")),
selected = "AGE",
multiple = FALSE,
fixed = FALSE
)
),
y = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")),
selected = "BMRKR1",
multiple = FALSE,
fixed = FALSE
)
),
color_by = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(
data[["ADSL"]],
c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1")
),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
size_by = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
selected = "AGE",
multiple = FALSE,
fixed = FALSE
)
),
row_facet = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
),
col_facet = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")),
selected = NULL,
multiple = FALSE,
fixed = FALSE
)
)
)
)
)
#> Initializing tm_g_scatterplot
if (interactive()) {
shinyApp(app$ui, app$server)
}