Learn R Programming

rsvd (version 2.0.0)

ggindplot: PCA observation scores

Description

Display observations in a plane defined by two retained principal components from rpca. Each point shows an observation's fitted scores, allowing patterns in the selected components to be compared across observations or supplied groups. Labels and group ellipses can be added. The optional ggplot2 package is required.

Usage

ggindplot(
  rpcaObj,
  pcs = c(1, 2),
  groups = NULL,
  alpha = 0.6,
  ellipse = TRUE,
  alpha.ellipse = 0.2,
  ind_labels = TRUE,
  ind_labels.names = NULL
)

Value

A ggplot2 plot object. Print the object to draw the plot, or add layers, labels, and themes with ggplot2.

Arguments

rpcaObj

An object returned by rpca, with real-valued scores. Complex factor maps are not supported. Fit with retx = TRUE so that rpcaObj$x is available.

pcs

Integer vector of length two selecting the retained principal components to plot, in horizontal and vertical order. The default is c(1, 2). Both indices must be finite integers within the retained component range.

groups

Optional factor with one entry for each row of rpcaObj$x, in the same order. The length must match the number of score rows; shorter inputs are not recycled. Groups control point colours and, when requested, ellipses. The default, NULL, uses one colour and draws no ellipse. If rpca omitted incomplete observations, supply groups for the retained rows only.

alpha

Numeric value between zero and one controlling point transparency, with zero fully transparent and one opaque. The default is 0.6.

ellipse

Logical; draw a filled data ellipse for each supplied group when TRUE (the default). The defaults of stat_ellipse give a multivariate-t ellipse at level 0.95. See Details for its interpretation.

alpha.ellipse

Numeric value between zero and one controlling ellipse transparency. The default is 0.2; ignored when no ellipse is drawn.

ind_labels

Logical; show a text label for each observation when TRUE (the default). Set to FALSE to reduce clutter.

ind_labels.names

Optional character vector with one label per row of rpcaObj$x, in the same order. By default, the score row names are used, or sequential row numbers when names are absent. Labels are displayed only when ind_labels = TRUE.

Author

N. Benjamin Erichson

Details

The horizontal and vertical coordinates are the columns of rpcaObj$x selected by pcs. These fitted scores retain the centering and scaling used in rpca; the plotting function does not standardize or recompute them. For randomized fits, they are the stored projected-SVD scores described in rpca.

Each axis label gives its component's share of rpcaObj$var, the total variance of the processed input. Variance in omitted components remains in the denominator, so a view of two components need not account for all of the variation.

When groups are supplied, point colours identify group membership and data ellipses summarize the spread of fitted scores within each group. The ellipses use the multivariate-t model in stat_ellipse, whose computation also requires the recommended package MASS. They do not estimate confidence regions for group means or test group separation. Small groups or degenerate score distributions may not support ellipse estimation; use ellipse = FALSE in that case.

See Also

rpca, ggbiplot, ggcorplot, ggscreeplot, ggplot, stat_ellipse

Examples

Run this code
if (requireNamespace("ggplot2", quietly = TRUE)) {
  set.seed(42)
  fit <- rpca(iris[, 1:4], k = 3)
  print(ggindplot(fit, pcs = c(1, 3), groups = iris$Species,
                  ellipse = FALSE, ind_labels = FALSE))
}

Run the code above in your browser using DataLab