Search code examples
rplotvegan

Environmental Vectors to CCA plot in vegan (R)


I'm performing a constrained ordination in the vegan package using CCA function. I have a matrix of species composition at various sites and a related environmental matrix.

invertcca<-cca(invert.rel~X100m, env)
plot(invertcca)

The default plot gives me both site and species scores, along with a vector displaying the environmental variable. It's messy, but here's what it looks like:

Default CCA plot

I was then playing around with customizing the plot. I got almost everything working except for adding the environmental vector back in. I did find a code for 'envfit' but I don't think it's right. It creates the arrow but in a different position than the plot above. I've included my code and an image below. Any suggestions?

colvec<-c("magenta", "seagreen", "deepskyblue")
fit <- envfit(invertcca~X100m, env)

plot(invertcca, main="Invert CCA", type="n")
with(env, points(invertcca,display="sites",col=colvec[Disturbance], cex=1.2, pch=21, bg=colvec[Disturbance]))
text(invertcca, display="species", cex=0.5, col="gray0")
with(env, legend("topright", legend=levels(Disturbance), col=colvec, pch=21, pt.bg=colvec))
plot(fit, cex=1.0, axis=TRUE)

Custom plot


Solution

  • From what I can tell, this might be related to your call for envfit. Try:

    fit <- envfit(invertcca~100m,env,perm=999,display="lc")

    I tried this using the varespec dataset in the vegan package and had the same problem until I followed the instructions in the example form the vegan manual.

    data(varespec)
    data(varechem)
    ord <- cca(varespec~Al,varechem)
    fit <- envfit(ord~Al,varechem,perm=999,display="lc")
    plot(ord)
    

    enter image description here

    plot(ord,type="n")
    plot(fit)
    points(ord)
    

    enter image description here

    hope this helps