| ggbiplot | R Documentation |
Display observations in a plane defined by two retained
principal components from rpca, with arrows showing the
corresponding variable directions. The combined view relates variation
among the observations to the variables used in the fit. The optional
ggplot2 package is required.
ggbiplot(
rpcaObj,
pcs = c(1, 2),
loadings = TRUE,
groups = NULL,
alpha = 0.6,
ellipse = TRUE,
alpha.ellipse = 0.2,
var_labels = TRUE,
var_labels.names = NULL,
ind_labels = TRUE,
ind_labels.names = 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 |
groups |
Optional factor with one entry for each row of |
alpha |
Numeric value between zero and one controlling point
transparency, with zero fully transparent and one opaque. The default is
|
ellipse |
Logical; draw a filled data ellipse for each supplied group
when |
alpha.ellipse |
Numeric value between zero and one controlling ellipse
transparency. The default is |
var_labels |
Logical; label the variable arrows when
|
var_labels.names |
Optional character vector with one label per row of
|
ind_labels |
Logical; show a text label for each observation when
|
ind_labels.names |
Optional character vector with one label per row of
|
Each point represents one observation, with coordinates taken
directly from rpcaObj$x. These fitted component scores reflect the
centering and scaling requested in rpca. The plotting function
leaves their normalization unchanged. Axis labels give each selected
component's share of the total processed variance in rpcaObj$var,
which includes variance outside the retained components.
Each arrow represents one variable. The loadings argument changes
its coordinates by including or omitting the component standard deviations.
Arrows and observations retain their respective loading and score scales;
the function does not rescale them to match visually.
For centered variables with unit sample variance and nonzero component
variance, the default coordinates equal the correlations with fitted scores
for a deterministic SVD. A randomized fit can introduce approximation error
in this interpretation. Other preprocessing choices give scaled directions
that need not be correlations. Use ggcorplot to examine the
directions separately with a unit circle.
When groups are supplied, data ellipses summarize the spread of fitted
scores within each group under the multivariate-t model used by
stat_ellipse. They do not estimate confidence
regions for group means or test group separation. The multivariate-t
computation also requires the recommended package MASS. Small
groups or degenerate score distributions may not support ellipse
estimation; use ellipse = FALSE in that case.
A ggplot2 plot object. Print the object to draw the plot, or add layers, labels, and themes with ggplot2.
N. Benjamin Erichson
rpca, ggindplot,
ggcorplot, ggscreeplot,
ggplot, stat_ellipse
if (requireNamespace("ggplot2", quietly = TRUE)) {
set.seed(42)
fit <- rpca(iris[, 1:4], k = 2)
p <- ggbiplot(fit, groups = iris$Species, ellipse = FALSE,
ind_labels = FALSE)
print(p + ggplot2::labs(title = "Iris scores and variable directions"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.