User Tools

Site Tools


en:hier-agglom_examples_rscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:hier-agglom_examples_rscript [2018/04/09 15:23] (current)
Line 1: Line 1:
 +<code rsplus>
 +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 ​
  
 +BCI.env <- read.delim ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​bci.env.txt'​)
 +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,)
 +</​code>​
en/hier-agglom_examples_rscript.txt · Last modified: 2018/04/09 15:23 (external edit)