library(ggplot2)
library(vegan)
library(robustbase)
data(dune)
data(dune.env)
pca <- vegan::rda(dune, scale = TRUE)
scores <- as.data.frame(vegan::scores(pca, display = "sites"))
scores$Management <- dune.env$Management
ggplot(scores, aes(PC1, PC2, group = Management, fill = Management)) +
stat_barrel(
method = "classic", kind = "se", conf = 0.95, geom_type = "polygon",
alpha = 0.4, color = "black"
) +
stat_barrel_centroid(method = "classic", shape = 3) +
stat_barrel_arrows(
ord = pca, matrix = dune,
labels = TRUE, labels.color = "blue",
arrow.color = "darkred", arrow.linetype = "solid",
labels.fontface = "bold", show.significant = TRUE,
labels.max.overlaps = Inf,
) +
stat_barrel_annotate(ord = pca, xpad = 0.05, ypad = 0.05) +
geom_point(aes(color = Management)) +
theme_minimal()
Run the code above in your browser using DataLab