# Analysis of community ecology data in R

David Zelený

### Others

Author: David Zelený en:hier-agglom_examples_rscript
```library (vegan)
data (BCI)  # example using Baro Colorado data
BCI.log <- log1p (BCI)  # first, log transform species data, which contains numbers of individuals
bc.dist <- vegdist (BCI.log, method = 'bray')
bc.dist
print (bc.dist, diag = TRUE)
#install.packages ('cluster') # install if necessary
library (cluster)
clust <- agnes (sqrt (bc.dist), method = 'ward.D2') # calculate Ward's algorithm
# on square-rooted Bray-Curtis distances
plot (clust, which = 2)
rect.hclust (clust, 5, border = 1:5)
groups <- cutree (clust, k = 5)
groups

plot (UTM.NS ~ UTM.EW, data = BCI.env, pch = groups, cex = 3)  # this is the simple version, only with symbols differentiating individual groups
plot (UTM.NS ~ UTM.EW, data = BCI.env, pch = groups+20, cex = 3, bg = groups, col = 'white') # this is more "colorful" option. Note that symbols now are 21 to 25, arguments 'bg' and 'col' which

# First, NMDS with Bray-Curtis distances
NMDS <- metaMDS (sqrt (vegdist (BCI.log)))  # note that I could use also "NMDS <- metaMDS (sqrt (bc.dist))" here
par (mfrow = c(1,2)) # I want to plot both plots into one figure, with two panels in one row
ordiplot (NMDS, type = 'n')
points (NMDS, pch = groups, col = groups)
legend ('topright', pch = 1:5, col = 1:5, legend = 1:5)

# Second, DCA ordination (implicitly using chi-square distance)
DCA <- decorana (BCI.log)
ordiplot (DCA, type = 'n', display = 'si')
points (DCA, pch = groups, col = groups)
legend ('topright', pch = 1:5, col = 1:5, legend = 1:5,)``` 