Display how variables are represented in a plane defined by two retained principal components. Arrows show their directions, optionally scaled by the component standard deviations, and a unit circle provides a reference for interpreting standardized fits. The optional ggplot2 package is required.
ggcorplot(
rpcaObj,
pcs = c(1, 2),
loadings = TRUE,
var_labels = FALSE,
var_labels.names = NULL,
alpha = 1,
top.n = NULL
)A ggplot2 plot object. Print the object to draw the plot, or add layers, labels, and themes with ggplot2.
An object returned by rpca, with
real-valued directions. Complex factor maps are not supported. Scores are
not needed, so fits made with retx = FALSE are supported.
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.
Logical; when TRUE (the default), multiply each
selected direction by its component standard deviation, so the coordinates
are rotation[, pcs] scaled columnwise by sdev[pcs].
When FALSE, plot the unscaled entries of rotation[, pcs].
Logical; show text labels for the variables
selected by top.n when TRUE. The default is FALSE.
Optional character vector with one label per row of
rpcaObj$rotation, in the original variable order. By default, the
rotation row names are used, or sequential variable numbers when names
are absent.
These names identify the endpoint markers and, when requested, the text
labels.
Numeric value between zero and one controlling
arrow transparency. The default is 1 (opaque).
Positive integer limiting the number of variables
selected for endpoint markers and text labels. Selection is by decreasing
arrow length in the plotted two-component plane. The default, NULL,
selects all variables; values larger than the number of variables are
clamped to that number. See Details for the marker display rule.
N. Benjamin Erichson
The direction coefficients describe how each original variable
enters a component. Multiplying a coefficient by the component standard
deviation also accounts for the variation captured by that component.
With loadings = TRUE, variable \(j\) therefore has coordinate
\(V_{ji}\sqrt{\lambda_i}\) on component
\(i\), where \(V\) is rotation and
\(\lambda_i\) is the corresponding eigenvalue. This is
the direction entry multiplied by sdev[i]. With
loadings = FALSE, the coordinates are the unscaled direction
coefficients, which changes relative arrow lengths and may change which
variables top.n selects.
For centered variables with unit sample variance and nonzero component variance, the scaled coordinates equal the correlations with fitted scores for a deterministic SVD. A randomized fit can introduce approximation error in this interpretation. In this setting, the unit circle helps show how well the selected component plane represents each variable. With unscaled or uncentered input, the coordinates need not be correlations and the circle serves as a visual reference. Equal horizontal and vertical scales preserve the circle's shape.
Every variable is shown by an arrow. To make a crowded plot easier to read,
top.n limits the variables selected for endpoint markers and, when
var_labels = TRUE, text labels. Selection uses arrow length within
the displayed plane, so the ranking applies only to these two components.
Endpoint markers are drawn only when the effective number selected is
less than 50.
Axis labels give each selected component's share of rpcaObj$var,
the total variance of the processed input. The denominator includes
variance outside the retained components.
rpca, ggbiplot,
ggindplot, ggscreeplot,
ggplot
if (requireNamespace("ggplot2", quietly = TRUE)) {
set.seed(42)
fit <- rpca(iris[, 1:4], k = 2, retx = FALSE)
# Label the three longest arrows in the selected component plane.
print(ggcorplot(fit, var_labels = TRUE, top.n = 3))
}
Run the code above in your browser using DataLab