### K-means
# Kompletni data o bruslarkach mam ulozena v dataframe bru
bru.6m<-bru[bru$sex=="m"&bru$instar==6,]
library(vegan)


bru.mat<-vegdist(decostand(bru.6m[,4:11], "standardize"), method="eucl")
km.bru<-cascadeKM(bru.mat, inf.gr=1, sup.gr = 10)
plot(km.bru, sortg=T, gridcol=0)

bru.klas<-kmeans(bru.mat, centers=7, nstart=100)

pca.1<-rda(bru.6m[,4:11]~1, scale=T)

aa<-ordiplot(pca.1, type='n')
points(aa, what="sites", col=bru.klas$cluster)
ordihull(aa, bru.6m$species)


#### 2 a 3
# Druhová data jsou uložená v objektu pako
pako.mat<-vegdist(log(pako.spe+1), method="bray")

hc.p<-hclust(pako.mat)
plot(hc.p)
plot(pako.mat, cophenetic(hc.p))
abline(b=1, a=0)

hc.p<-hclust(pako.mat, method="single")
plot(hc.p)
plot(pako.mat, cophenetic(hc.p))
abline(b=1, a=0)

hc.p<-hclust(pako.mat, method="average")
plot(hc.p)
plot(pako.mat, cophenetic(hc.p))
abline(b=1, a=0)

