Skip to content

CCA plot

2 messages · Maria Kernecker, Gavin Simpson

#
On Tue, 2012-11-27 at 15:35 -0500, Maria Kernecker wrote:
I'm not sure what you tried but this works for me:

require(vegan)
data(varespec)
data(varechem)
## Common but bad way: use all variables you happen to have in your
## environmental data matrix
vare.cca <- cca(varespec ~ ., data = varechem)

## build up plot
plot(vare.cca, display = c("sites","species"), scaling = 3)
## add the biplot arrows (though this could be done in the plot() call
text(vare.cca, scaling = 3, display = "bp")
One way would be:

sig <- anova(vare.cca, by = "term")
## get ones with p values less than or equal to some threshold
ind <- with(sig, head(`Pr(>F)` <= 0.05, -1))

## now get the bp scores
scrs <- scores(vare.cca, display = "bp", scaling = 3)
## and take the ones that are signif
scrs <- scrs[ind, ]

## draw plot and add them
plot(vare.cca, display = c("sites","species"), scaling = 3)
## scale then as per vegan
mul <- vegan:::ordiArrowMul(scrs)
arrows(0, 0, scrs[,1] * mul, scrs[,2] * mul, length = 0.05,
       col = "blue")
text(scrs * mul * 1.1, labels = rownames(scrs), cex = 0.9,
     col = "blue")

Not that I recommend this "pruning" a CCA...

HTH

G