[R] CCA plot

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Nov 28 10:58:49 CET 2012


On Tue, 2012-11-27 at 15:35 -0500, Maria Kernecker wrote:
> Hi, I have a couple questions about fitting environmental (land use
> factors, plant species presence-absence, and soil variables) constraints to
> my CCA biplot. 1. After successfully plotting species and site scores in my
> CCA, I have been trying to insert the biplot arrows of the environmental
> constraints in my data set using the text() function. When I do that, the
> plot changes completely. Is there some code or a sample script you could
> let me know about?

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")

>  2. I would like to include only the environment
> constraints that are significant at conf=0.95, but am not sure that I can
> do that in a CCA biplot. I was hoping that this way I could make my plot
> less crowded.

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

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list