Module conducts principal component analysis (PCA) on a given dataset and offers different ways of visualizing the outcomes, including elbow plot, circle plot, biplot, and eigenvector plot. Additionally, it enables dynamic customization of plot aesthetics, such as opacity, size, and font size, through UI inputs.
Usage
tm_a_pca(
label = "Principal Component Analysis",
dat,
plot_height = c(600, 200, 2000),
plot_width = NULL,
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
ggplot2_args = teal.widgets::ggplot2_args(),
rotate_xaxis_labels = FALSE,
font_size = c(12, 8, 20),
alpha = c(1, 0, 1),
size = c(2, 1, 8),
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.- dat
(
data_extract_specorlistof multipledata_extract_spec) specifying columns used to compute PCA.- 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.- ggtheme
(
character) optional,ggplot2theme to be used by default. Defaults to"gray".- ggplot2_args
-
(
ggplot2_args) optional, object created byteal.widgets::ggplot2_args()with settings for all the plots or named list ofggplot2_argsobjects for plot-specific settings. The argument is merged with options variableteal.ggplot2_argsand default module setup.List names should match the following:
c("default", "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot").For more details see the vignette:
vignette("custom-ggplot2-arguments", package = "teal.widgets"). - rotate_xaxis_labels
(
logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).- font_size
-
(
numeric) optional, specifies font size. It controls the font size for plot titles, axis labels, and legends.If vector of
length == 1then the font sizes will have a fixed size.while vector of
value,min, andmaxallows dynamic adjustment.
- alpha
-
(
integer(1)orinteger(3)) optional, specifies point opacity.When the length of
alphais one: the plot points will have a fixed opacity.When the length of
alphais three: the plot points opacity are dynamically adjusted based on vector ofvalue,min, andmax.
- size
-
(
integer(1)orinteger(3)) optional, specifies point size.When the length of
sizeis one: the plot point sizes will have a fixed size.When the length of
sizeis three: the plot points size are dynamically adjusted based on vector ofvalue,min, andmax.
- 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.
Decorating Module
This module generates the following objects, which can be modified in place using decorators:
elbow_plot(ggplot)circle_plot(ggplot)biplot(ggplot)eigenvector_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_a_pca(
..., # arguments for module
decorators = list(
elbow_plot = teal_transform_module(...), # applied to the `elbow_plot` output
circle_plot = teal_transform_module(...), # applied to the `circle_plot` output
biplot = teal_transform_module(...), # applied to the `biplot` output
eigenvector_plot = teal_transform_module(...) # applied to the `eigenvector_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)
USArrests <- USArrests
})
app <- init(
data = data,
modules = modules(
tm_a_pca(
"PCA",
dat = data_extract_spec(
dataname = "USArrests",
select = select_spec(
choices = variable_choices(
data = data[["USArrests"]], c("Murder", "Assault", "UrbanPop", "Rape")
),
selected = c("Murder", "Assault"),
multiple = TRUE
),
filter = NULL
)
)
)
)
#> Initializing tm_a_pca
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_a_pca(
"PCA",
dat = data_extract_spec(
dataname = "ADSL",
select = select_spec(
choices = variable_choices(
data = data[["ADSL"]], c("BMRKR1", "AGE", "EOSDY")
),
selected = c("BMRKR1", "AGE"),
multiple = TRUE
),
filter = NULL
)
)
)
)
#> Initializing tm_a_pca
if (interactive()) {
shinyApp(app$ui, app$server)
}