| pca.plot | R Documentation |
Ordination of Principal Components from the output of a Principal Components Analysis performed by prcomp function (stats package). Require a factor object with groups, which enable the plot to feature colored groups and convex hulls (if desired).
pca.plot(
PCA.out = NULL,
groups = NULL,
col.gp = grDevices::rainbow(length(levels(groups))),
conv.hulls = NULL,
col.conv = grDevices::rainbow(length(levels(conv.hulls))),
PCs = c(1, 2),
main = "Ordination of PCA coordinates",
sp.as = "points",
sp.text = NULL,
cross.origin = TRUE,
lwd = 1,
lty = "dotted",
leg = TRUE,
leg.labels = groups,
leg.pos = "topright",
cex.leg = 1,
cex = 1,
cex.axis = 1,
cex.lab = 1,
cex.main = 1
)
PCA.out |
the output of a Principal Components Analysis performed by |
groups |
groups to use as colors and/or convex hulls. Must be a |
col.gp |
a |
conv.hulls |
groups to use for convex hulls. Must be a |
col.conv |
a |
PCs |
a vector of length two with the Principal Components intended for the plot. By default: |
main |
main title of output plot. Should be presented between quotation marks. By default: |
sp.as |
enables one to choose between ploting elements as |
sp.text |
only applies when |
cross.origin |
A logical. If |
lwd |
only applies when |
lty |
only applies when |
leg |
a logical. If |
leg.labels |
only applies when |
leg.pos |
only applies when |
cex.leg |
only applies when |
cex |
same as in |
cex.axis |
same as in |
cex.lab |
same as in |
cex.main |
same as in |
Require the output of prcomp and a vector with groups to plot. In addition, it is also possible to include convex hulls around each group (i.e. conv.hulls) and to control the colors intended for each group (i.e. col.gp) and for each convex hull (i.e. col.conv).
Pedro Rocha
Rocha, P. & Romano, P. (2021) The shape of sound: A new R package that crosses the bridge between Bioacoustics and Geometric Morphometrics. Methods in Ecology and Evolution, 12(6), 1115-1121.
prcomp, palette, rgb, rainbow, legend
Useful links:
data(eig.sample)
# PCA using 3D semilandmark coordinates
pca.eig.sample <- stats::prcomp(geomorph::two.d.array(eig.sample))
# Verify names for each acoustic unit and the order in which they appear
dimnames(eig.sample)[[3]]
# Create factor to use as groups in subsequent ordination plot
sample.gr <- factor(c(rep("centralis", 3), rep("cuvieri", 3), rep("kroyeri", 3)))
# Clear current R plot to prevent errors
grDevices::dev.off()
# Plot result of Principal Components Analysis
pca.plot(PCA.out = pca.eig.sample, groups = sample.gr, conv.hulls = sample.gr,
main="PCA of 3D coordinates", leg=TRUE, leg.pos = "top")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.