Description Usage Arguments Details Value See Also Examples
Extract information from an object returned by a function performing Principal Component Analysis and produce a plot of observations, of variables, or a biplot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## S3 method for class 'prcomp'
autoplot(object, mapping = aes(), data = NULL,
dimensions = c(1, 2), which = "rows", scaling = which,
n.max.labels = 100, ...)
## S3 method for class 'PCA'
autoplot(object, mapping = aes(), data = NULL,
dimensions = c(1, 2), which = "rows", scaling = which,
n.max.labels = 100, ...)
## S3 method for class 'rda'
autoplot(object, mapping = aes(), data = NULL,
dimensions = c(1, 2), which = "rows", scaling = which,
n.max.labels = 100, ...)
## S3 method for class 'pca'
autoplot(object, mapping = aes(), data = NULL,
dimensions = c(1, 2), which = "rows", scaling = which,
n.max.labels = 100, ...)
## S3 method for class 'pcaRes'
autoplot(object, mapping = aes(), data = NULL,
dimensions = c(1, 2), which = "rows", scaling = which,
n.max.labels = 100, ...)
|
object |
an object returned by a function performing Principal Component Analysis. |
mapping |
a call to aes() specifying additional mappings between variables and plot aesthetics. By default, positions |
data |
the original dataset, to be concatenated with the output when extracting row scores. When |
dimensions |
vector giving the indexes of the principal components to extract. Typically two are extracted to create a plot. |
which |
the plot to produce: either plot "rows", "lines", "observations", "objects", "individuals", "sites" (which are all treated as synonyms), or plot "columns", "variables", "descriptors", "species" (which are, again, synonyms), or produce a "biplot". All can be abbreviated. By default, observations are plotted. |
scaling |
scaling for the scores. Can be
By default, scaling is adapted to the type of scores extracted (scaling 1 for row scores, scaling 2 for column scores, and scaling 3 when scores are extracted for a biplot). |
n.max.labels |
maximum number of observation labels to plot. Let |
... |
passed to the various geoms; can be used to set further aesthetics. |
The object is passed to the appropriate augment
method, defined in pca_tidiers
, which extracts the scores, possibly the original data, and other relevant information from the PCA object. The resulting data.frame
is plotted with:
geom_point
:for observations points,
geom_text
or geom_text_repel
:for observations labels,
geom_segment
:for variables vectors.
A ggplot2 object defining the plot.
Functions to perform PCA: prcomp
in package stats
, PCA
in package factoMineR
, rda
in package vegan
, dudi.pca
in package ade4
, pca
in package pcaMethods
(on bioconductor).
Other PCA.related.functions: ca_tidiers
,
pca_tidiers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | pca <- prcomp(USArrests, scale=TRUE)
autoplot(pca)
autoplot(pca, which="variables")
autoplot(pca, which="biplot") # defaults to scaling=3
autoplot(pca, which="biplot", scaling=1)
autoplot(pca, which="biplot", scaling=2, n.max.labels=0)
# add further aesthetic mappings
names(augment(pca, data=USArrests))
autoplot(pca, data=USArrests, mapping=aes(alpha=.cos2))
autoplot(pca, data=USArrests, mapping=aes(alpha=.cos2, size=.contrib))
# including from the original data
autoplot(pca, data=USArrests, mapping=aes(alpha=.cos2, color=Murder))
# aesthetics can also be set
autoplot(pca, mapping=aes(alpha=.cos2), color="darkblue", size=3)
if (require("FactoMineR")) {
pca <- FactoMineR::PCA(USArrests, graph=FALSE)
autoplot(pca)
autoplot(pca, which="variables")
# with FactoMineR, the data is present by default and can be mapped
names(augment(pca))
autoplot(pca, mapping=aes(alpha=.cos2, color=Murder))
}
if (require("vegan")) {
pca <- vegan::rda(USArrests, scale=TRUE)
plot(pca)
autoplot(pca, which="biplot", scaling=2)
autoplot(pca)
}
if (require("ade4")) {
pca <- ade4::dudi.pca(USArrests, nf=4, scannf=FALSE)
biplot(pca)
autoplot(pca, which="biplot", scaling=1)
}
if (require("pcaMethods")) {
pca <- pcaMethods::pca(USArrests, scale="uv", nPcs=4)
biplot(pca)
autoplot(pca, which="biplot")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.