| plot_category_pca | R Documentation |
Projects an arbitrary multidimensional acoustic feature set onto two principal components and visualizes the result with ggplot2. This is a diagnostic plot for high-dimensional workflows: metric estimates should still be computed on the full feature set when that is the intended analysis.
plot_category_pca(
data,
features,
category_col,
group_col = NULL,
components = c(1L, 2L),
center = TRUE,
scale. = TRUE,
points = TRUE,
ellipses = TRUE,
point_alpha = 0.65,
point_size = 1.8,
equal_axes = TRUE,
facet_scales = c("fixed", "free", "free_x", "free_y")
)
data |
Data frame containing category labels and acoustic features. |
features |
Character vector of two or more numeric feature columns used for PCA. |
category_col |
String; category column. |
group_col |
Optional grouping column used for facets. |
components |
Two positive integers giving principal components to plot. |
center, scale. |
Passed to |
points |
Logical; if |
ellipses |
Logical; if |
point_alpha |
Point transparency. |
point_size |
Point size. |
equal_axes |
Logical; if |
facet_scales |
Scales passed to |
A ggplot2 plot object. The fitted prcomp object and
variance-explained table are stored as "pca" and
"variance_explained" attributes.
set.seed(2026)
features <- paste0("mfcc", 1:5)
vowels <- data.frame(
vowel = rep(c("ih", "eh"), each = 50),
matrix(rnorm(100 * length(features)), ncol = length(features))
)
names(vowels)[-1] <- features
vowels[vowels$vowel == "eh", features[1:2]] <- vowels[vowels$vowel == "eh", features[1:2]] + 0.8
if (requireNamespace("ggplot2", quietly = TRUE)) {
plot_category_pca(vowels, features = features, category_col = "vowel")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.