plot.princomp.BData.grouped: Plot Method for Grouped PCA of Distributional Data

View source: R/PCA.R

plot.princomp.BData.groupedR Documentation

Plot Method for Grouped PCA of Distributional Data

Description

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.

Usage

## S3 method for class 'princomp.BData.grouped'
plot(
  x,
  type = c("screeplot", "variance", "scores", "eigenfunctions", "loadings", "covariance",
    "reconstruction", "boxplot"),
  mfrow = NULL,
  main = NULL,
  ...
)

Arguments

x

An object of class 'princomp.BData.grouped' as returned by princomp.BData with a 'group' argument.

type

Character string specifying the type of plot. Same options as plot.princomp.BData: '"screeplot"', '"variance"', '"scores"', '"loadings"', '"covariance"', or '"reconstruction"'.

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 plot.princomp.BData.

Details

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.

Value

Invisibly returns the grouped PCA object.

Author(s)

Matthias Templ

See Also

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()

Examples

# 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))


DistributionalDDA documentation built on Oct. 20, 2026, 5:06 p.m.