| plot.princomp.BData.grouped | R Documentation |
Creates multi-panel comparison plots for grouped PCA results. Each group is shown in a separate panel, allowing visual comparison of PCA results across different subgroups of the data.
## S3 method for class 'princomp.BData.grouped'
plot(
x,
type = c("screeplot", "variance", "scores", "eigenfunctions", "loadings", "covariance",
"reconstruction", "boxplot"),
mfrow = NULL,
main = NULL,
...
)
x |
An object of class 'princomp.BData.grouped' as returned by
|
type |
Character string specifying the type of plot. Same options as
|
mfrow |
Optional vector of c(nrow, ncol) for panel layout. If 'NULL', panels are arranged automatically in a single row. |
main |
Character string for overall title. If 'NULL', group names are used as individual panel titles. |
... |
Additional arguments passed to |
This function sets up a multi-panel plotting layout and calls
plot.princomp.BData for each group. The layout is automatically
determined based on the number of groups, but can be overridden using 'mfrow'.
Common use cases:
Compare loadings across groups to see if different subgroups have different modes of variation.
Compare screeplots to assess if dimensionality differs by group.
Compare score plots to see internal structure within each group.
Invisibly returns the grouped PCA object.
Matthias Templ
princomp.BData for performing grouped PCA.
plot.princomp.BData for single-group plot options.
Other PCA:
biplot.princomp.BData(),
plot.princomp.BData(),
plot.princomp.BData.multivariate(),
predict.princomp.BData(),
princomp.BData(),
screeplot.princomp.BData(),
summary.princomp.BData()
# Create grouped PCA using age distribution data
data("age")
# Set up basis
rmAge <- ReferenceMeasureUniform(0, 100)
B2Age <- BayesSpace(rmAge)
basisAge <- BayesSpaceBasis(B2Age, nbasis = 7)
# Create histograms and convert to splines
breaks <- c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 100)
ageHist <- BDataDensityHistograms(age$distributions, breaks = breaks, basis = basisAge)
ageSplines <- as.BDataSplines(as.BDataDensities(ageHist))
# Perform grouped PCA by sex
pcaGrouped <- princomp(ageSplines, group = age$data$sex)
pcaGrouped
# Compare screeplots by group
plot(pcaGrouped, type = "screeplot")
# Compare loadings by group
plot(pcaGrouped, type = "loadings", npcs = 2)
# Custom layout (2 rows)
plot(pcaGrouped, type = "scores", mfrow = c(2, 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.