Schefferville - transitions; K-means clustering and comparisons of these clusters

Tammy L. Elliott

Date: March 21, 2015

R version 3.1.0

# set global chunk options: 
library(knitr)
opts_chunk$set(cache=FALSE, fig.align='center')

Plot PCoA with 3 groupings based on k-means clustering for environmental distances

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
vasc.env.3<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.3[,1]
y<-vasc.env.3[,2]
plot(vasc.env.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black")
ordispider(vasc.env.3, vasc.env.clust.3$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.3, vasc.env.clust.3$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(vasc.env.3), cex=0.4)

vasc.env.3<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.3[,1]
y<-vasc.env.3[,2]
plot(vasc.env.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black")
ordispider(vasc.env.3, vasc.env.clust.3$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.3, vasc.env.clust.3$cluster, col="grey70")
box(lwd=2)

### Plot PCoA with 4 groupings based on k-means clustering for environmental distances

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
vasc.env.4<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.4[,1]
y<-vasc.env.4[,2]
plot(vasc.env.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black")
ordispider(vasc.env.4, vasc.env.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.4, vasc.env.clust.4$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(vasc.env.4), cex=0.4)

vasc.env.4<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.4[,1]
y<-vasc.env.4[,2]
plot(vasc.env.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black")
ordispider(vasc.env.4, vasc.env.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.4, vasc.env.clust.4$cluster, col="grey70")
box(lwd=2)

Plot PCoA with 5 groupings based on k-means clustering for environmental distances

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
vasc.env.5<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.5[,1]
y<-vasc.env.5[,2]
plot(vasc.env.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black")
ordispider(vasc.env.5, vasc.env.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.5, vasc.env.clust.5$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(vasc.env.5), cex=0.4)

vasc.env.5<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.5[,1]
y<-vasc.env.5[,2]
plot(vasc.env.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black")
ordispider(vasc.env.5, vasc.env.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.5, vasc.env.clust.5$cluster, col="grey70")
box(lwd=2)

Non-abundance weighted Chao’s beta diversity

sp.dist.abd <- dist(vasc.pairs.abd0.mat)

# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((sp.dist.abd),2,15)
plot(ccas.dist,sortq=TRUE)

veg.abd.k.clust<-kmeans(sp.dist.abd, 3)
veg.abd.k.clust.4<-kmeans(sp.dist.abd,4)
veg.abd.k.clust.5<-kmeans(sp.dist.abd,5)

PCoA on Chao’s beta diversity with three clusters based on K-means clustering

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
veg.abd<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-veg.abd[,1]
y<-veg.abd[,2]
plot(veg.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with three clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd, veg.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd, veg.abd.k.clust$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(veg.abd), cex=0.4)

veg.abd<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(veg.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with three clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd, veg.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd, veg.abd.k.clust$cluster, col="grey70")
box(lwd=2)

PCoA on Chao’s beta diversity with four clusters based on K-means clustering

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
veg.abd.4<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-veg.abd.4[,1]
y<-veg.abd.4[,2]
plot(veg.abd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with four clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd.4, veg.abd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd.4, veg.abd.k.clust.4$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(veg.abd.4), cex=0.4)

veg.abd.4<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(veg.abd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with four clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd.4, veg.abd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd.4, veg.abd.k.clust.4$cluster, col="grey70")
box(lwd=2)

PCoA on Chao’s beta diversity with five clusters based on K-means clustering

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
veg.abd.5<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-veg.abd.5[,1]
y<-veg.abd.5[,2]
plot(veg.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with five clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd.5, veg.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd.5, veg.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(veg.abd.5), cex=0.4)

veg.abd.5<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(veg.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with five clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd.5, veg.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd.5, veg.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)

Abundance weighted Chao’s beta diversity

# Abundance weighted Chao's beta diversity
abd.sp.dist.abd <- dist(vasc.pairs.abd1.mat)

# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((sp.dist.abd),2,15)
plot(ccas.dist,sortq=TRUE)

abd.veg.abd.k.clust<-kmeans(abd.sp.dist.abd, 3)
abd.veg.abd.k.clust.4<-kmeans(abd.sp.dist.abd,4)
abd.veg.abd.k.clust.5<-kmeans(abd.sp.dist.abd,5)

Principal Coordinate Analysis (PCoA) on Chao’s abundance-weighted beta diversity with three clusters based on K-means clustering (vasculars)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.veg.abd<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.veg.abd[,1]
y<-abd.veg.abd[,2]
plot(abd.veg.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with three clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd, abd.veg.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd, abd.veg.abd.k.clust$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.veg.abd), cex=0.4)

abd.veg.abd<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.veg.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with three clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd, abd.veg.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd, abd.veg.abd.k.clust$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) on Chao’s abundance-weighted beta diversity with four clusters based on K-means clustering (vasculars)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.veg.abd.4<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.veg.abd.4[,1]
y<-abd.veg.abd.4[,2]
plot(abd.veg.abd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with four clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd.4, abd.veg.abd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd.4, abd.veg.abd.k.clust.4$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.veg.abd.4), cex=0.4)

abd.veg.abd.4<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.veg.abd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with four clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd.4, abd.veg.abd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd.4, abd.veg.abd.k.clust.4$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) on Chao’s abundance-weighted diversity with five clusters based on K-means clustering (vasculars)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.veg.abd.5<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.veg.abd.5[,1]
y<-abd.veg.abd.5[,2]
plot(abd.veg.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with five clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd.5, abd.veg.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd.5, abd.veg.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.veg.abd.5), cex=0.4)

abd.veg.abd.5<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.veg.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with five clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd.5, abd.veg.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd.5, abd.veg.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)

Pairwise phylogenetic distances (not weighted) between pairs of plots

#Pairwise phylogenetic distances (not weighted) between pairs of plots
trans.dist<-dist(vasc.ph.pairs.abd0.mat)
# Make euclidean for further analyzes
head(sqrt(trans.dist))
## [1] 1.5915041 1.7298445 0.9721087 1.4180747 1.5518220 1.1105326
is.euclid(trans.dist)
## Warning in is.euclid(trans.dist): Zero distance(s)
## [1] TRUE
# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((trans.dist),2,15)
plot(ccas.dist,sortq=TRUE)

vasc.dist.clust.two<-kmeans(trans.dist,2)
vasc.dist.clust.three<-kmeans(trans.dist,3)
vasc.dist.clust.four<-kmeans(trans.dist,4)
vasc.dist.clust.five<-kmeans(trans.dist,5)

Principal Coordinate Analysis (PCoA) with three clusters based on K-means clustering on Chao’s phylogenetic beta diversity pairwise distances (vasculars)

#Plot PCoA with 3 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
vasc.abd.k.3<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.abd.k.3[,1]
y<-vasc.abd.k.3[,2]
plot(vasc.abd.k.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.3, vasc.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.3, vasc.dist.clust.three$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(vasc.abd.k.3), cex=0.4)

vasc.abd.k.3<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(vasc.abd.k.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.3, vasc.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.3, vasc.dist.clust.three$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with four clusters based on K-means clustering on Chao’s phylogenetic beta diversity pairwise distances (vasculars)

#Plot PCoA with 4 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
vasc.abd.k.4<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.abd.k.4[,1]
y<-vasc.abd.k.4[,2]
plot(vasc.abd.k.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.4, vasc.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.4, vasc.dist.clust.four$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(vasc.abd.k.4), cex=0.4)

vasc.abd.k.4<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(vasc.abd.k.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.4, vasc.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.4, vasc.dist.clust.four$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with five clusters based on K-means clustering on Chao’s phylogenetic beta diversity pairwise distances (vasculars)

#Plot PCoA with 5 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
vasc.abd.k.5<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.abd.k.5[,1]
y<-vasc.abd.k.5[,2]
plot(vasc.abd.k.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.5, vasc.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.5, vasc.dist.clust.five$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(vasc.abd.k.5), cex=0.5)

vasc.abd.k.5<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(vasc.abd.k.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.5, vasc.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.5, vasc.dist.clust.five$cluster, col="grey70")
box(lwd=2)

Pairwise phylogenetic distances (not weighted) between pairs of plots

#Pairwise phylogenetic distances (not weighted) between pairs of plots
abd.trans.dist<-dist(vasc.ph.pairs.abd1.mat)
# Make euclidean for further analyzes
head(sqrt(abd.trans.dist))
## [1] 1.430152 1.860524 1.735937 1.877979 1.578909 1.782176
is.euclid(abd.trans.dist)
## [1] TRUE
# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((abd.trans.dist),2,15)
plot(ccas.dist,sortq=TRUE)

abd.vasc.dist.clust.two<-kmeans(abd.trans.dist,2)
abd.vasc.dist.clust.three<-kmeans(abd.trans.dist,3)
abd.vasc.dist.clust.four<-kmeans(abd.trans.dist,4)
abd.vasc.dist.clust.five<-kmeans(abd.trans.dist,5)

Principal Coordinate Analysis (PCoA) with three clusters based on K-means clustering on Chao’s abundance-weighted phylogenetic beta diversity pairwise distances (vasculars)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.vasc.abd.k.3<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.vasc.abd.k.3[,1]
y<-abd.vasc.abd.k.3[,2]
plot(abd.vasc.abd.k.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.3, abd.vasc.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.3, abd.vasc.dist.clust.three$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.vasc.abd.k.3), cex=0.4)

abd.vasc.abd.k.3<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.vasc.abd.k.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.3, abd.vasc.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.3, abd.vasc.dist.clust.three$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with four clusters based on K-means clustering on Chao’s abundance-weighted phylogenetic beta diversity pairwise distances (vasculars)

#Plot PCoA with 4 groupings based on k-means clustering for abundance-weighted Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.vasc.abd.k.4<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.vasc.abd.k.4[,1]
y<-abd.vasc.abd.k.4[,2]
plot(abd.vasc.abd.k.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.4, abd.vasc.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.4, abd.vasc.dist.clust.four$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.vasc.abd.k.4), cex=0.4)

abd.vasc.abd.k.4<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.vasc.abd.k.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.4, abd.vasc.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.4, abd.vasc.dist.clust.four$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with five clusters based on K-means clustering on Chao’s abundance-weighted phylogenetic beta diversity pairwise distances (vasculars)

#Plot PCoA with 5 groupings based on k-means clustering for abundance-weighted Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.vasc.abd.k.5<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.vasc.abd.k.5[,1]
y<-abd.vasc.abd.k.5[,2]
plot(abd.vasc.abd.k.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.5, abd.vasc.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.5, abd.vasc.dist.clust.five$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.vasc.abd.k.5), cex=0.5)

abd.vasc.abd.k.5<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.vasc.abd.k.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.5, abd.vasc.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.5, abd.vasc.dist.clust.five$cluster, col="grey70")
box(lwd=2)

Angiosperms non-abundance weighted Chao’s beta diversity

angio.dist.bd <- dist(angiopairs.abd0.mat)

# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((angio.dist.bd),2,15)
plot(ccas.dist,sortq=TRUE)

angio.dist.bd.k.clust<-kmeans(angio.dist.bd, 3)
angio.dist.bd.k.clust.4<-kmeans(angio.dist.bd,4)
angio.dist.bd.k.clust.5<-kmeans(angio.dist.bd,5)

Principal Coordinate Analysis (PCoA) on Chao’s beta diversity with three clusters based on K-means clustering (angiosperms)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
pcoa.angio.dist.bd<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-pcoa.angio.dist.bd[,1]
y<-pcoa.angio.dist.bd[,2]
plot(pcoa.angio.dist.bd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with three clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd, angio.dist.bd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd, angio.dist.bd.k.clust$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(pcoa.angio.dist.bd), cex=0.4)

pcoa.angio.dist.bd<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(pcoa.angio.dist.bd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with three clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd, angio.dist.bd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd, angio.dist.bd.k.clust$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) on Chao’s beta diversity with four clusters based on K-means clustering (angiosperms)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
pcoa.angio.dist.bd.4<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-pcoa.angio.dist.bd.4[,1]
y<-pcoa.angio.dist.bd.4[,2]
plot(pcoa.angio.dist.bd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with four clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd.4, angio.dist.bd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd.4, angio.dist.bd.k.clust.4$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(pcoa.angio.dist.bd.4), cex=0.4)

pcoa.angio.dist.bd.4<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(pcoa.angio.dist.bd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with four clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd.4, angio.dist.bd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd.4, angio.dist.bd.k.clust.4$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) on Chao’s beta diversity with five clusters based on K-means clustering (angiosperms)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
pcoa.angio.dist.bd.5<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-pcoa.angio.dist.bd.5[,1]
y<-pcoa.angio.dist.bd.5[,2]
plot(pcoa.angio.dist.bd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with five clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd.5, angio.dist.bd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd.5, angio.dist.bd.k.clust.5$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(pcoa.angio.dist.bd.5), cex=0.4)

pcoa.angio.dist.bd.5<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(pcoa.angio.dist.bd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with five clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd.5, angio.dist.bd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd.5, angio.dist.bd.k.clust.5$cluster, col="grey70")
box(lwd=2)

Abundance weighted Chao’s beta diversity for angiosperms only

angio.dist.abd <- dist(angiopairs.abd1.mat)

# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((angio.dist.abd),2,15)
plot(ccas.dist,sortq=TRUE)

abd.angio.abd.k.clust<-kmeans(angio.dist.abd, 3)
abd.angio.abd.k.clust.4<-kmeans(angio.dist.abd,4)
abd.angio.abd.k.clust.5<-kmeans(angio.dist.abd,5)

Principal Coordinate Analysis (PCoA) on Chao’s abundance-weighted beta diversity with three clusters based on K-means clustering (angiosperms)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.angio.abd<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.angio.abd[,1]
y<-abd.angio.abd[,2]
plot(abd.angio.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with three clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd, abd.angio.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd, abd.angio.abd.k.clust$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.angio.abd), cex=0.4)

abd.angio.abd<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.angio.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with three clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd, abd.angio.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd, abd.angio.abd.k.clust$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) on Chao’s abundance-weighted beta diversity with four clusters based on K-means clustering (angiosperms)

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.angio.abd.4<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.angio.abd.4[,1]
y<-abd.angio.abd.4[,2]
plot(abd.angio.abd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with four clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd.4, abd.angio.abd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd.4, abd.angio.abd.k.clust.4$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.angio.abd.4), cex=0.4)

abd.angio.abd.4<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.angio.abd.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with four clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd.4, abd.angio.abd.k.clust.4$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd.4, abd.angio.abd.k.clust.4$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) on Chao’s abundance-weighted beta diversity with five clusters based on K-means clustering (angiosperms)``

#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
abd.angio.abd.5<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-abd.angio.abd.5[,1]
y<-abd.angio.abd.5[,2]
plot(abd.angio.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with five clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd.5, abd.angio.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd.5, abd.angio.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(abd.angio.abd.5), cex=0.4)

abd.angio.abd.5<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.angio.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with five clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd.5, abd.angio.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd.5, abd.angio.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)

Pairwise phylogenetic distances (not weighted) between pairs of plots - angiosperms

angio.trans.dist<-dist(angioph.pairs.abd0.mat)
# Make euclidean for further analyzes
head(sqrt(angio.trans.dist))
## [1] 1.298212 1.607143 1.321965 1.326673 1.795988 1.035656
is.euclid(angio.trans.dist)
## Warning in is.euclid(angio.trans.dist): Zero distance(s)
## [1] TRUE
# Suggestions for optimal K-means clusters 
ccas.dist<-cascadeKM((angio.trans.dist),2,15)
plot(ccas.dist,sortq=TRUE)

angio.dist.clust.three<-kmeans(angio.trans.dist,3)
angio.dist.clust.four<-kmeans(angio.trans.dist,4)
angio.dist.clust.five<-kmeans(angio.trans.dist,5)

Principal Coordinate Analysis (PCoA) with three clusters based on K-means clustering on Chao’s phylogenetic beta diversity pairwise distances (angiosperms)

#Plot PCoA with 3 groupings based on k-means clustering for not abundance-weighted Phylogenetic beta diversity values (angiosperms)
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
angio.distk.3<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-angio.distk.3[,1]
y<-angio.distk.3[,2]
plot(angio.distk.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.3, angio.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.3, angio.dist.clust.three$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(angio.distk.3), cex=0.4)

angio.distk.3<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.distk.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.3, angio.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.3, angio.dist.clust.three$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with four clusters based on K-means clustering on Chao’s phylogenetic beta diversity pairwise distances (angiosperms)

#Plot PCoA with 4 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
angio.distk.4<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-angio.distk.4[,1]
y<-angio.distk.4[,2]
plot(angio.distk.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.4, angio.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.4, angio.dist.clust.four$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(angio.distk.4), cex=0.4)

angio.distk.4<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.distk.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.4, angio.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.4, angio.dist.clust.four$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with five clusters based on K-means clustering on Chao’s phylogenetic beta diversity pairwise distances (angiosperms)

#Plot PCoA with 5 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
angio.distk.5<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-angio.distk.5[,1]
y<-angio.distk.5[,2]
plot(angio.distk.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.5, angio.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.5, angio.dist.clust.five$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(angio.distk.5), cex=0.5)

angio.distk.5<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.distk.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.5, angio.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.5, angio.dist.clust.five$cluster, col="grey70")
box(lwd=2)

Pairwise phylogenetic distances (weighted) between pairs of plots

abd.angio.dist<-dist(angioph.pairs.abd1.mat)
# Make euclidean for further analyzes
head(sqrt(abd.angio.dist))
## [1] 1.052225 1.161007 1.407660 1.220391 1.890975 1.659321
# Suggestions for optimal K-means clusters 
ccas.dist.angio<-cascadeKM((abd.angio.dist),2,15)
plot(ccas.dist.angio,sortq=TRUE)

abd.angio.dist.clust.two<-kmeans(abd.angio.dist,2)
abd.angio.dist.clust.three<-kmeans(abd.angio.dist,3)
abd.angio.dist.clust.four<-kmeans(abd.angio.dist,4)
abd.angio.dist.clust.five<-kmeans(abd.angio.dist,5)

Principal Coordinate Analysis (PCoA) with three clusters based on K-means clustering on abundance-weighted Chao’s phylogenetic beta diversity pairwise distances (angiosperms)

#Plot PCoA with 3 groupings based on k-means clustering for abundance-weighted Phylogenetic beta diversity values (angiosperms)
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
angio.abd.k.3<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-angio.abd.k.3[,1]
y<-angio.abd.k.3[,2]
plot(angio.abd.k.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.3, abd.angio.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.3, abd.angio.dist.clust.three$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(angio.abd.k.3), cex=0.4)

angio.abd.k.3<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.abd.k.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.3, abd.angio.dist.clust.three$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.3, abd.angio.dist.clust.three$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with four clusters based on K-means clustering on abundance-weighted Chao’s phylogenetic beta diversity pairwise distances (angiosperms)

#Plot PCoA with 4 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
angio.abd.k.4<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-angio.abd.k.4[,1]
y<-angio.abd.k.4[,2]
plot(angio.abd.k.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.4, abd.angio.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.4, abd.angio.dist.clust.four$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(angio.abd.k.4), cex=0.4)

angio.abd.k.4<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.abd.k.4, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with four\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.4, abd.angio.dist.clust.four$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.4, abd.angio.dist.clust.four$cluster, col="grey70")
box(lwd=2)

Principal Coordinate Analysis (PCoA) with five clusters based on K-means clustering on abundance-weighted Chao’s phylogenetic beta diversity pairwise distances (angiosperms)

#Plot PCoA with 5 groupings based on k-means clustering for Phylogenetic beta diversity values
#dev.new(width=11.8, height=8)
par(mfrow=c(1,2))
angio.abd.k.5<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-angio.abd.k.5[,1]
y<-angio.abd.k.5[,2]
plot(angio.abd.k.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with five\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.5, abd.angio.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.5, abd.angio.dist.clust.five$cluster, col="grey70")
box(lwd=2)
text(x, y, rownames(angio.abd.k.5), cex=0.5)

angio.abd.k.5<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.abd.k.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.5, abd.angio.dist.clust.five$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.5, abd.angio.dist.clust.five$cluster, col="grey70")
box(lwd=2)

My objective classifications of habitat type

#try polygons per habitat type
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.1.1
#dev.new(width=8, height=6)
hab<-site[,c(3:5), drop=FALSE]
hab.types<-hab[,1, drop=FALSE]
fen<-hab[which(hab$Habitat.Description=="Fen"),]
smf<-hab[which(hab$Habitat.Description=="Spruce moss"),]
smf.fen<-hab[which(hab$Habitat.Description=="Spruce moss - Fen"),]

tun<-hab[which(hab$Habitat.Description=="Tundra"),]
shr<-hab[which(hab$Habitat.Description=="Shrubs"),]
tun.shr<-hab[which(hab$Habitat.Description=="Tundra - Shrubs"),]

#use convex hull function to plot habitats
find_hull <- function(df) {
    res.ch <- df[chull(hab$Latitude..WGS.84.datum., hab$Longitude..WGS.84.datum), ]
    res <- bezier(res.ch)
    res <- data.frame(x=res$Latitude..WGS.84.datum.,y=res$hab$Longitude..WGS.84.datum)
    res$z <- res$z
    res
  }

hab.ggplot<-ggplot(hab, aes(hab$Latitude..WGS.84.datum., hab$Longitude..WGS.84.datum., colour = hab$Habitat.Description)) + geom_point(size=4) +
theme_bw() + theme(panel.border = element_rect(colour="black"), panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))+ xlab("Latitude") + ylab("Longitude")   +
    ggtitle("Habitat Types for Plots in Large \nSampling Grid (Tammy's Classifications)")

hab.ggplot+theme(axis.title.y = element_text(size=16, vjust=1),axis.title.x = element_text(size=16), axis.text.x  = element_text(size=12), axis.text.y= element_text(size=12,angle=90,hjust=0.5))+
theme(plot.title = element_text(vjust = 2, size=15, face="bold")) + theme(legend.title = element_text(size=12))+
  scale_linetype_discrete("Habitat Type") +
  scale_shape_discrete("Habitat Type") +
  scale_colour_discrete("Habitat Type")

Locations on grid of the three groupings

#make dataframe for large transects; with plot number, Habitat.description, latitude, longitude
site.trunc<-site[,c(3:5)]

#dev.new(width=15, height=8.5)
par(mfrow=c(3,3))
myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.env.clust.3$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on \nK-means clustering of environmental distances", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")



myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(veg.abd.k.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means \nclustering of Chao's beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.veg.abd.k.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's weighted beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.dist.clust.three$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.vasc.dist.clust.three$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's weighted phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")



myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.bd.k.clust$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.angio.abd.k.clust$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's weighted beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")



myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.clust.three$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.angio.dist.clust.three$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's weighted phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3"), pch=21,
    pt.bg=c("black","grey50", "white"),col="black",  cex=1.1, bty="n")

Locations on grid of the four groupings

#Show on grid where four clusters correspond to:
#dev.new(width=15, height=8.5)
par(mfrow=c(3,3))
myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.env.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on \nK-means clustering of environmental distances", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(veg.abd.k.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means \nclustering of Chao's beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.veg.abd.k.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's weighted beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.dist.clust.four$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.vasc.dist.clust.four$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's weighted phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.bd.k.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.angio.abd.k.clust.4$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's weighted beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.clust.four$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")



myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.angio.dist.clust.four$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's weighted phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("topleft", c("Group 1","Group 2","Group 3", "Group 4"), pch=21,
    pt.bg=c("black", "gray30", "gray80","white"),col="black",  cex=0.95, bty="n")

Locations on grid of the five groupings

# Show on grid locations of five clusters for nine different methods
#dev.new(width=15, height=8.5)
par(mfrow=c(3,3))
myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.env.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on \nK-means clustering of environmental distances", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(veg.abd.k.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means \nclustering of Chao's beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.veg.abd.k.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's weighted beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.dist.clust.five$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.vasc.dist.clust.five$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's weighted phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.bd.k.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.angio.abd.k.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's weighted beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.clust.five$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(abd.angio.dist.clust.five$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's weighted phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

# Compare numbers among clusters
size.3
##         Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc Phy.Abd.Bdiv.vasc
## Group 1       42        45            55            72               100
## Group 2       86        57            64            61                 7
## Group 3       48        74            57            43                69
##         Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Group 1         38             64             67                 58
## Group 2         60             71             72                 56
## Group 3         78             41             37                 62
size.4
##      Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc Phy.Abd.Bdiv.vasc
## [1,]       34        34            38            31                 6
## [2,]       45        56            53            34                30
## [3,]       55        55            32            71                89
## [4,]       42        31            53            40                51
##      Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## [1,]         32             49            101                 54
## [2,]         35             32             29                 44
## [3,]         56             53             25                 22
## [4,]         53             42             21                 56
size.5
##         Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc Phy.Abd.Bdiv.vasc
## Group 1       32        30            32            72                44
## Group 2       10        43            53            16                51
## Group 3       23        11            25            40                46
## Group 4       37        56            20            16                29
## Group 5       74        36            46            32                 6
##         Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Group 1         22             52             17                 56
## Group 2         28             34             50                 41
## Group 3         45             15             30                 25
## Group 4         49             28             26                 32
## Group 5         32             47             53                 22
# Show within group sum of squares
withinss.3
##         Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc Phy.Abd.Bdiv.vasc
## Group 1 35.97047  3306.602      5366.880      4102.819          3034.183
## Group 2 49.24220  2240.539      7128.447      1734.179          2276.252
## Group 3 34.96651  4170.653      3671.677      1566.483          3235.393
##         Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Group 1   2572.728       9226.259       3625.735           3508.737
## Group 2   2868.798       6542.412       2146.382           7202.903
## Group 3   5039.601       3356.442       1405.717           1445.043
withinss.4
##          Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc Phy.Abd.Bdiv.vasc
## Group 1  9.450085  2095.118      2652.304      979.5204          2036.833
## Group 2 30.605065  2737.750      4909.335      878.4684          1109.265
## Group 3 19.079068  2128.677      1727.124     4030.3091          2504.894
## Group 4 35.970475  1236.884      3115.649      581.3797          1263.229
##         Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Group 1   1330.889       3202.646      3545.8550          6921.3836
## Group 2   2201.212       2125.532       922.9113          1748.6033
## Group 3   2776.249       5520.618       825.8882           794.3296
## Group 4   2168.654       3535.861       380.6387           792.5493
withinss.5
##         Env.dist  Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc Phy.Abd.Bdiv.vasc
## Group 1 20.41801 1837.63838      1727.124    4102.81900          484.4514
## Group 2  1.30683 1382.63917      4909.335      69.77186         1198.3972
## Group 3 12.17893   98.57614      1257.154     581.37972          987.9169
## Group 4 18.02882 2891.87654      1213.403     197.82068         1067.8001
## Group 5 34.96041 1333.60517      2274.467     757.22465         2036.8328
##         Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Group 1   1051.949       5419.677       636.1840           792.5493
## Group 2   1759.896       2395.241      1413.9549          1486.5580
## Group 3   1434.520       1116.326      1019.9035           764.2236
## Group 4   1976.840       1537.045       477.7594          3401.8341
## Group 5   1330.889       2838.457      1278.5311           794.3296
# Compare sum-of-squares within and between clusters
totss.all<-rbind(totss.3, totss.4, totss.5)
rownames(totss.all)<-c("Total SS 3", "Total SS 4", "Total SS 5")
totss.all
##            Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc
## Total SS 3 586.5044  21517.85      31209.84      18917.66
## Total SS 4 586.5044  21517.85      31209.84      18917.66
## Total SS 5 586.5044  21517.85      31209.84      18917.66
##            Phy.Abd.Bdiv.vasc Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio
## Total SS 3          21098.37   23217.48        35774.2       20389.45
## Total SS 4          21098.37   23217.48        35774.2       20389.45
## Total SS 5          21098.37   23217.48        35774.2       20389.45
##            Phy.Abd.Bdiv.angio
## Total SS 3           35238.74
## Total SS 4           35238.74
## Total SS 5           35238.74
tot.withinss.all<-rbind(tot.withinss.3, tot.withinss.4, tot.withinss.5)
rownames(tot.withinss.all)<-c("Tot. within SS 3", "Tot. within SS 4", "Tot. within SS 5")
tot.withinss.all
##                   Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc
## Tot. within SS 3 120.17918  9717.793      16167.00      7403.481
## Tot. within SS 4  95.10469  8198.430      12404.41      6469.678
## Tot. within SS 5  86.89300  7544.335      11381.48      5709.016
##                  Phy.Abd.Bdiv.vasc Bdiv.angio Abd.Bdiv.angio
## Tot. within SS 3          8545.829  10481.128       19125.11
## Tot. within SS 4          6914.221   8477.004       14384.66
## Tot. within SS 5          5775.398   7554.095       13306.75
##                  Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Tot. within SS 3       7177.834          12156.683
## Tot. within SS 4       5675.293          10256.866
## Tot. within SS 5       4826.333           7239.495
betweenss<-rbind(betweenss.3, betweenss.4, betweenss.5)
rownames(betweenss)<-c("Between SS 3", "Between SS 4", "Between SS 5")
betweenss
##              Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc
## Between SS 3 466.3252  11800.06      15042.84      11514.18
## Between SS 4 491.3997  13319.42      18805.43      12447.99
## Between SS 5 499.6114  13973.51      19828.36      13208.65
##              Phy.Abd.Bdiv.vasc Bdiv.angio Abd.Bdiv.angio Phy.Bdiv.angio
## Between SS 3          12552.54   12736.35       16649.08       13211.61
## Between SS 4          14184.15   14740.48       21389.54       14714.15
## Between SS 5          15322.98   15663.39       22467.45       15563.11
##              Phy.Abd.Bdiv.angio
## Between SS 3           23082.06
## Between SS 4           24981.87
## Between SS 5           27999.25
# Compare within/between
with.betw<-rbind(tot.withinss.3/betweenss.3, tot.withinss.4/betweenss.4, tot.withinss.5/betweenss.5)
rownames(with.betw)<-c("Within/Between SS 3", "Within/Between SS 4", "Within/Between SS 5")
with.betw
##                      Env.dist Bdiv.vasc Abd.Bdiv.vasc Phy.Bdiv.vasc
## Within/Between SS 3 0.2577154 0.8235378     1.0747311     0.6429880
## Within/Between SS 4 0.1935384 0.6155245     0.6596188     0.5197369
## Within/Between SS 5 0.1739212 0.5399025     0.5740003     0.4322180
##                     Phy.Abd.Bdiv.vasc Bdiv.angio Abd.Bdiv.angio
## Within/Between SS 3         0.6808045  0.8229301      1.1487186
## Within/Between SS 4         0.4874610  0.5750834      0.6725090
## Within/Between SS 5         0.3769110  0.4822773      0.5922677
##                     Phy.Bdiv.angio Phy.Abd.Bdiv.angio
## Within/Between SS 3      0.5432974          0.5266724
## Within/Between SS 4      0.3857030          0.4105723
## Within/Between SS 5      0.3101136          0.2585603

Mantel plot comparisons

mantel.statistic
##                Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio Phy.Bdiv.angio
## Env.dist          1.000     0.470         0.398      0.412          0.131
## Bdiv.vasc         0.470     1.000         0.629      0.972          0.582
## Phy.Bdiv.vasc     0.398     0.629         1.000      0.529          0.577
## Bdiv.angio        0.412     0.972         0.529      1.000          0.608
## Phy.Bdiv.angio    0.131     0.582         0.577      0.608          1.000
mantel.statistic.abd
##                    Env.dist Abd.Bdiv.vasc Phy.Abd.Bdiv.vasc Abd.Bdiv.angio
## Env.dist              1.000         0.377             0.150          0.304
## Abd.Bdiv.vasc         0.377         1.000             0.384          0.923
## Phy.Abd.Bdiv.vasc     0.150         0.384             1.000          0.277
## Abd.Bdiv.angio        0.304         0.923             0.277          1.000
## Phy.Abd.Bdiv.angio    0.117         0.519             0.320          0.585
##                    Phy.Abd.Bdiv.angio
## Env.dist                        0.117
## Abd.Bdiv.vasc                   0.519
## Phy.Abd.Bdiv.vasc               0.320
## Abd.Bdiv.angio                  0.585
## Phy.Abd.Bdiv.angio              1.000
mantel.statistic.signif
##                Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio Phy.Bdiv.angio
## Env.dist          1.000     0.001         0.001      0.001          0.001
## Bdiv.vasc         0.001     1.000         0.001      0.001          0.001
## Phy.Bdiv.vasc     0.001     0.001         1.000      0.001          0.001
## Bdiv.angio        0.001     0.001         0.001      1.000          0.001
## Phy.Bdiv.angio    0.001     0.001         0.001      0.001          1.000
mantel.statistic.abd.signif
##                    Env.dist Abd.Bdiv.vasc Phy.Abd.Bdiv.vasc Abd.Bdiv.angio
## Env.dist              1.000         0.001             0.001          0.001
## Abd.Bdiv.vasc         0.001         1.000             0.001          0.001
## Phy.Abd.Bdiv.vasc     0.001         0.001             1.000          0.001
## Abd.Bdiv.angio        0.001         0.001             0.001          1.000
## Phy.Abd.Bdiv.angio    0.001         0.001             0.001          0.001
##                    Phy.Abd.Bdiv.angio
## Env.dist                        0.001
## Abd.Bdiv.vasc                   0.001
## Phy.Abd.Bdiv.vasc               0.001
## Abd.Bdiv.angio                  0.001
## Phy.Abd.Bdiv.angio              1.000

Partition comparisons

Use Rand index Values between 0 and 1, with 0 indicating that the two data clusters do not agree on Any pair of points and 1 indicating that the data clusters are exactly the same.

Partition comparison between three cluster groupings

compPart
##                Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio Phy.Bdiv.angio
## Env.dist           1.00      0.66          0.70       0.63           0.59
## Bdiv.vasc          0.66      1.00          0.71       0.92           0.70
## Phy.Bdiv.vasc      0.70      0.71          1.00       0.67           0.62
## Bdiv.angio         0.63      0.92          0.67       1.00           0.71
## Phy.Bdiv.angio     0.59      0.70          0.62       0.71           1.00

Partition comparison between three cluster groupings for abundance-weighted groupings

compPart.abd
##                    Env.dist Abd.Bdiv.vasc Phy.Abd.Bdiv.vasc Abd.Bdiv.angio
## Env.dist               1.00          0.66              0.59           0.63
## Abd.Bdiv.vasc          0.66          1.00              0.63           0.76
## Phy.Abd.Bdiv.vasc      0.59          0.63              1.00           0.57
## Abd.Bdiv.angio         0.63          0.76              0.57           1.00
## Phy.Abd.Bdiv.angio     0.55          0.64              0.51           0.61
##                    Phy.Abd.Bdiv.angio
## Env.dist                         0.55
## Abd.Bdiv.vasc                    0.64
## Phy.Abd.Bdiv.vasc                0.51
## Abd.Bdiv.angio                   0.61
## Phy.Abd.Bdiv.angio               1.00

Partition comparison between four cluster groupings

compPart.4
##                Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio Phy.Bdiv.angio
## Env.dist           1.00      0.70          0.70       0.70           0.59
## Bdiv.vasc          0.70      1.00          0.69       0.97           0.65
## Phy.Bdiv.vasc      0.70      0.69          1.00       0.69           0.60
## Bdiv.angio         0.70      0.97          0.69       1.00           0.64
## Phy.Bdiv.angio     0.59      0.65          0.60       0.64           1.00

Partition comparison between four cluster groupings for abundance-weighted groupings

compPart.4.abd
##                    Env.dist Abd.Bdiv.vasc Phy.Abd.Bdiv.vasc Abd.Bdiv.angio
## Env.dist               1.00          0.67              0.64           0.67
## Abd.Bdiv.vasc          0.67          1.00              0.63           0.91
## Phy.Abd.Bdiv.vasc      0.64          0.63              1.00           0.61
## Abd.Bdiv.angio         0.67          0.91              0.61           1.00
## Phy.Abd.Bdiv.angio     0.63          0.69              0.57           0.69
##                    Phy.Abd.Bdiv.angio
## Env.dist                         0.63
## Abd.Bdiv.vasc                    0.69
## Phy.Abd.Bdiv.vasc                0.57
## Abd.Bdiv.angio                   0.69
## Phy.Abd.Bdiv.angio               1.00

Partition comparison between five cluster groupings

compPart.5
##                Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio Phy.Bdiv.angio
## Env.dist           1.00      0.73          0.69       0.71           0.69
## Bdiv.vasc          0.73      1.00          0.71       0.77           0.70
## Phy.Bdiv.vasc      0.69      0.71          1.00       0.69           0.68
## Bdiv.angio         0.71      0.77          0.69       1.00           0.74
## Phy.Bdiv.angio     0.69      0.70          0.68       0.74           1.00

Partition comparison between five cluster groupings for abundance-weighted groupings

compPart.5.abd
##                    Env.dist Abd.Bdiv.vasc Phy.Abd.Bdiv.vasc Abd.Bdiv.angio
## Env.dist               1.00          0.68              0.67           0.68
## Abd.Bdiv.vasc          0.68          1.00              0.71           0.90
## Phy.Abd.Bdiv.vasc      0.67          0.71              1.00           0.69
## Abd.Bdiv.angio         0.68          0.90              0.69           1.00
## Phy.Abd.Bdiv.angio     0.67          0.73              0.72           0.74
##                    Phy.Abd.Bdiv.angio
## Env.dist                         0.67
## Abd.Bdiv.vasc                    0.73
## Phy.Abd.Bdiv.vasc                0.72
## Abd.Bdiv.angio                   0.74
## Phy.Abd.Bdiv.angio               1.00

Optimal number of grouping according to Calinski criteria

#vasc.env.clust.3
#veg.abd.k.clust
#abd.veg.abd.k.clust
vasc.dist.clust.eight<-kmeans(trans.dist,8)
abd.vasc.dist.clust.fourteen<-kmeans(abd.trans.dist,14)
angio.dist.bd.k.clust.2<-kmeans(angio.dist.bd, 2)
#abd.angio.abd.k.clust.5
angio.dist.clust.two<-kmeans(angio.trans.dist, 2)
abd.angio.dist.clust.seven<-kmeans(angio.dist.abd,7)

Show PCoA’s with clusters for optimal numbers of groupings

# Not - abundance weighted
# Plot PCoA with 3 groupings based on k-means clustering for environmental distances
#dev.new(width=11.8, height=8)
par(mfrow=c(2,3))
vasc.env.3<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
x<-vasc.env.3[,1]
y<-vasc.env.3[,2]
plot(vasc.env.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.env.3, vasc.env.clust.3$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.3, vasc.env.clust.3$cluster, col="grey70")
box(lwd=2)


veg.abd<-cmdscale(sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(veg.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with three clusters based on K-means clustering", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(veg.abd, veg.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(veg.abd, veg.abd.k.clust$cluster, col="grey70")
box(lwd=2)

vasc.abd.k.8<-cmdscale(trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(vasc.abd.k.8, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with eight\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.abd.k.8, vasc.dist.clust.eight$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.abd.k.8, vasc.dist.clust.eight$cluster, col="grey70")
box(lwd=2)

pcoa.angio.dist.bd.2<-cmdscale(angio.dist.bd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(pcoa.angio.dist.bd.2, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's beta \ndiversity with two clusters based on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(pcoa.angio.dist.bd.2, angio.dist.bd.k.clust.2$cluster, col="grey40", label=TRUE)
ordiellipse(pcoa.angio.dist.bd.2, angio.dist.bd.k.clust.2$cluster, col="grey70")
box(lwd=2)

angio.distk.2<-cmdscale(angio.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.distk.2, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with two\nclusters based on K-means clustering on Chao's phylogenetic \nbeta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.distk.2, angio.dist.clust.two$cluster, col="grey40", label=TRUE)
ordiellipse(angio.distk.2, angio.dist.clust.two$cluster, col="grey70")
box(lwd=2)

Show PCoA’s with clusters for optimal numbers of groupings (abundance-weighted)

#abundance-weighted
#Plot PCoA with 3 groupings based on k-means clustering for environmental distances
#dev.new(width=11.8, height=8)
par(mfrow=c(2,3))
vasc.env.3<-cmdscale(site.env.dist, k = 54, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(vasc.env.3, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with three \nclusters based on K-means clustering on \npairwise environmental distances", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(vasc.env.3, vasc.env.clust.3$cluster, col="grey40", label=TRUE)
ordiellipse(vasc.env.3, vasc.env.clust.3$cluster, col="grey70")
box(lwd=2)

abd.veg.abd<-cmdscale(abd.sp.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.veg.abd, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with three clusters based on K-means clustering (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.veg.abd, abd.veg.abd.k.clust$cluster, col="grey40", label=TRUE)
ordiellipse(abd.veg.abd, abd.veg.abd.k.clust$cluster, col="grey70")
box(lwd=2)

abd.vasc.abd.k.14<-cmdscale(abd.trans.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.vasc.abd.k.14, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with fourteen\nclusters based on K-means clustering on Chao's abundance-weighted \nphylogenetic beta diversity pairwise distances (vasculars)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.vasc.abd.k.14, abd.vasc.dist.clust.fourteen$cluster, col="grey40", label=TRUE)
ordiellipse(abd.vasc.abd.k.14, abd.vasc.dist.clust.fourteen$cluster, col="grey70")
box(lwd=2)

abd.angio.abd.5<-cmdscale(angio.dist.abd, k = 100, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(abd.angio.abd.5, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) on Chao's abundance-weighted \nbeta diversity with five clusters \nbased on K-means clustering (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(abd.angio.abd.5, abd.angio.abd.k.clust.5$cluster, col="grey40", label=TRUE)
ordiellipse(abd.angio.abd.5, abd.angio.abd.k.clust.5$cluster, col="grey70")
box(lwd=2)

angio.abd.k.7<-cmdscale(abd.angio.dist, k = 75, eig = FALSE, add = FALSE, x.ret = FALSE)
plot(angio.abd.k.7, type="n", xlab="", ylab="", main="Principal Coordinate Analysis (PCoA) with seven\nclusters based on K-means clustering on abundance-weighted \nChao's phylogenetic beta diversity pairwise distances (angiosperms)", cex=1, pch=16, col="black", cex.main=0.9)
ordispider(angio.abd.k.7, abd.angio.dist.clust.seven$cluster, col="grey40", label=TRUE)
ordiellipse(angio.abd.k.7, abd.angio.dist.clust.seven$cluster, col="grey70")
box(lwd=2)

Partition comparison for optimal number of groups

compPart.optim
##                Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio Phy.Bdiv.angio
## Env.dist           1.00      0.66          0.68       0.50           0.57
## Bdiv.vasc          0.66      1.00          0.73       0.66           0.66
## Phy.Bdiv.vasc      0.68      0.73          1.00       0.46           0.59
## Bdiv.angio         0.50      0.66          0.46       1.00           0.51
## Phy.Bdiv.angio     0.57      0.66          0.59       0.51           1.00

Partition comparison for optimal number of groups for abundance-weighted groupings

compPart.optim.abd
##                    Env.dist Abd.Bdiv.vasc Phy.Abd.Bdiv.vasc Abd.Bdiv.angio
## Env.dist               1.00          0.66              0.63           0.65
## Abd.Bdiv.vasc          0.66          1.00              0.72           0.75
## Phy.Abd.Bdiv.vasc      0.63          0.72              1.00           0.78
## Abd.Bdiv.angio         0.65          0.75              0.78           1.00
## Phy.Abd.Bdiv.angio     0.64          0.75              0.83           0.89
##                    Phy.Abd.Bdiv.angio
## Env.dist                         0.64
## Abd.Bdiv.vasc                    0.75
## Phy.Abd.Bdiv.vasc                0.83
## Abd.Bdiv.angio                   0.89
## Phy.Abd.Bdiv.angio               1.00

Tammy’s classification per habitat type reduced to five different groupings

library(ggplot2)
#dev.new(width=8, height=6)
hab<-site[,c(3:5), drop=FALSE]
hab.types<-hab[,1, drop=FALSE]
# Show number of times that each habitat type represented
table(hab.types[,1])
## 
##                         Fen                      Shrubs 
##                          17                          31 
##               Spruce lichen      Spruce lichen - Shrubs 
##                           2                           2 
##                 Spruce moss           Spruce moss - Fen 
##                          67                          16 
##        Spruce moss - Shrubs Spruce moss - Spruce lichen 
##                           4                           6 
##                      Tundra             Tundra - Shrubs 
##                          23                           8
#Change values so that less levels - split categories go into the smaller of the two factors
# put Spruce lichen - shrubs into Spruce lichen
# put Spruce moss - Spruce lichen into Spruce lichen
# put Spruce moss - Shrubs into Spruce moss
# put Spruce moss - Fen into Fen
# put Tundra - shrubs into Tundra

library(plyr)
## Warning: package 'plyr' was built under R version 3.1.1
hab.types.smaller<-revalue(hab.types[,1], c("Spruce lichen - Shrubs"="Spruce lichen" , "Spruce moss - Spruce lichen"="Spruce lichen",
    "Spruce moss - Shrubs"="Spruce moss", "Spruce moss - Fen" = "Fen", "Tundra - Shrubs"="Tundra"))
table(hab.types.smaller)
## hab.types.smaller
##           Fen        Shrubs Spruce lichen   Spruce moss        Tundra 
##            33            31            10            71            31
hab.new<-cbind(hab.types.smaller,hab[,c(2:3)])

hab.new.ggplot<-ggplot(hab.new, aes(hab.new$Latitude..WGS.84.datum., hab.new$Longitude..WGS.84.datum., colour = hab.new$hab.types.smaller)) + geom_point(size=4) + 
theme_bw() + theme(panel.border = element_rect(colour="black"), panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))+ xlab("Latitude") + ylab("Longitude")   +
    ggtitle("Habitat Types for Plots in Large Sampling Grid \n(Tammy's Classifications with Regroupings)")

hab.new.ggplot+theme(axis.title.y = element_text(size=16, vjust=1),axis.title.x = element_text(size=16), axis.text.x  = element_text(size=12), axis.text.y= element_text(size=12,angle=90,hjust=0.5))+
theme(plot.title = element_text(vjust = 2, size=15, face="bold")) + theme(legend.title = element_text(size=12))+
  scale_linetype_discrete("Habitat Type") +
  scale_shape_discrete("Habitat Type") +
  scale_colour_discrete("Habitat Type")

Plot Tammy’s classifications with other 5 cluster groupings (without abundance-weighted groupings)

# Plot this with other non-abundance weighted grid representations

#dev.new(width=15, height=8.5)
par(mfrow=c(2,3))

myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(hab.new$hab.types.smaller))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on \nTammy's clasifications (5 groups)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")




myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.env.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on \nK-means clustering of environmental distances", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")


myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(veg.abd.k.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means \nclustering of Chao's beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")



myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(vasc.dist.clust.five$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups based on K-means clustering \nof Chao's phylogenetic beta diversity (vasculars)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")



cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.bd.k.clust.5$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")



myColorRamp <- function(colors, values) {
    v <- (values - min(values))/diff(range(values))
    x <- colorRamp(colors)(v)
    rgb(x[,1], x[,2], x[,3], maxColorValue = 255)
}

cols <- myColorRamp(c("black", "gray25", "gray50", "gray85", "white"), as.numeric(angio.dist.clust.five$cluster))
colfunc <- colorRampPalette(c("black", "gray25", "gray50", "gray85", "white"))
par(mar=c(5.1,4.1,4.1,2.1))
plot(site.trunc$Latitude..WGS.84.datum., site.trunc$Longitude..WGS.84.datum., xlab="Latitude", ylab="Longitude",
bg=cols, pch=21, col="black",cex=1.75, cex.lab=1.5, cex.axis=1.25, main="Locations of different groups from K-means clustering \nof Chao's phylogenetic beta diversity (angiosperms)", cex.main=1.25)
xl <- 1
yb <- -2.3
xr <- 1.5
yt <- 2.7

legend("bottomright", c("Group 1","Group 2","Group 3", "Group 4", "Group 5"), pch=21,
    pt.bg=c("black", "gray25", "gray50", "gray85", "white"),col="black",  cex=0.85,  bty="n")

Comparing partitions of five groupings with Tammy five group classifications (for non-abundance weighted data)

compPart.5.tam
##                Tammy Class Env.dist Bdiv.vasc Phy.Bdiv.vasc Bdiv.angio
## Tammy Class           1.00     0.76      0.70          0.67       0.71
## Env.dist              0.76     1.00      0.73          0.69       0.71
## Bdiv.vasc             0.70     0.73      1.00          0.71       0.77
## Phy.Bdiv.vasc         0.67     0.69      0.71          1.00       0.69
## Bdiv.angio            0.71     0.71      0.77          0.69       1.00
## Phy.Bdiv.angio        0.68     0.69      0.70          0.68       0.74
##                Phy.Bdiv.angio
## Tammy Class              0.68
## Env.dist                 0.69
## Bdiv.vasc                0.70
## Phy.Bdiv.vasc            0.68
## Bdiv.angio               0.74
## Phy.Bdiv.angio           1.00