plot.rpca: PCA summary plots

View source: R/plots.R

plot.rpcaR Documentation

PCA summary plots

Description

Summarize an object returned by rpca with plots of retained variance and of variables and observations in a component plane. A scree plot shows how much variation the fit captures; factor maps display the corresponding directions and fitted scores.

Usage

## S3 method for class 'rpca'
plot(x, ...)

Arguments

x

An object returned by rpca. Factor maps are intended for real-valued loadings and scores.

...

Named arguments for ggscreeplot, ggcorplot, or ggindplot. Each argument is passed only to helpers that accept it. For example, type selects the scree-plot quantity, pcs selects components for both factor maps, and groups is used only for the individual factor map. Names must be exact and unique; unknown or unnamed arguments are rejected. An explicit pcs value must contain two finite integer component indices within the retained range, even when a factor map is unavailable.

Details

The function draws the available plots in sequence on the active graphics device. The scree plot shows the variance captured by the retained components. With at least two components, a variable factor map then shows their directions in the selected plane. An individual factor map follows when fitted observation scores are available from retx = TRUE. A fit with one retained component therefore produces only a scree plot; a fit with at least two components and retx = FALSE produces the scree and variable factor plots.

Factor maps use components one and two by default. Supply pcs to inspect another pair of retained components. Any observation groups or labels must correspond to the fitted score rows, after incomplete training observations have been omitted. The ggplot2 package must be installed. Call the plotting helpers directly when a particular plot is needed for further customization or saving.

Value

The last ggplot2 plot drawn, returned invisibly. This is the individual factor map when available, otherwise the variable factor map or the scree plot.

Author(s)

N. Benjamin Erichson

See Also

rpca, ggscreeplot, ggcorplot, ggindplot, ggbiplot.

Examples

if (requireNamespace("ggplot2", quietly = TRUE)) {
  set.seed(42)
  fit <- rpca(iris[, 1:4], k = 2)
  last_plot <- plot(fit, type = "ratio", pcs = c(1, 2),
                    groups = iris$Species, ind_labels = FALSE,
                    ellipse = FALSE)

  # Request a single plot directly for further customization or saving.
  scree <- ggscreeplot(fit, type = "cum")
}


rsvd documentation built on Nov. 2, 2026, 5:06 p.m.