| ggcorplot | R Documentation |
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
)
rpcaObj |
An object returned by |
pcs |
Integer vector of length two selecting the retained principal
components to plot, in horizontal and vertical order. The default is
|
loadings |
Logical; when |
var_labels |
Logical; show text labels for the variables
selected by |
var_labels.names |
Optional character vector with one label per row of
|
alpha |
Numeric value between zero and one controlling
arrow transparency. The default is |
top.n |
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, |
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.
A ggplot2 plot object. Print the object to draw the plot, or add layers, labels, and themes with ggplot2.
N. Benjamin Erichson
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))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.