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
)
Arguments
- label
(
character(1)
) Label shown in the navigation item for the module or module group. Formodules()
defaults to"root"
. SeeDetails
.- dat
(
data_extract_spec
orlist
of multipledata_extract_spec
) specifying columns used to compute PCA.- 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.- ggtheme
(
character
) optional,ggplot2
theme 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_args
objects for plot-specific settings. The argument is merged with options variableteal.ggplot2_args
and 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 == 1
then the font sizes will have a fixed size.while vector of
value
,min
, andmax
allows dynamic adjustment.
- 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
.
- 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
.
- 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.
Examples
library(teal.widgets)
# general data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
USArrests <- USArrests
})
datanames(data) <- "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
),
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by PCA Module")
)
)
)
)
#> [INFO] 2024-03-05 18:46:02.7099 pid:1279 token:[] teal.modules.general Initializing tm_a_pca
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
ADSL <- rADSL
})
datanames(data) <- "ADSL"
join_keys(data) <- default_cdisc_join_keys[datanames(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
),
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by PCA Module")
)
)
)
)
#> [INFO] 2024-03-05 18:46:02.8401 pid:1279 token:[] teal.modules.general Initializing tm_a_pca
if (interactive()) {
shinyApp(app$ui, app$server)
}