###klasifikace

head(ext)
ext.s <- scale(ext)
head(ext.s)

ext.s <- as.data.frame(ext.s)
mean(ext.s$Altitude)
sd(ext.s$Altitude)

apply(ext.s, 2, sd)
apply(ext.s, 2, mean)
colMeans(ext.s)

set.seed(1234)
clust.clim <- kmeans(ext.s[ , c("Temperature", "Precipitation")],
                     centers = 3, iter.max = 100, nstart = 10)
clust.clim

my.col <- c("blue", "red", "yellow", "pink", "brown", "orange",
            "violet")


plot(forest[, c("X", "Y")], pch=21, cex=1.2,
     bg=my.col[clust.clim$cluster])

boxplot(ext$Temperature ~ clust.clim$cluster, col=my.col)

boxplot(ext$Precipitation ~ clust.clim$cluster, col=my.col)

library(vegan)

clust.env <- cascadeKM(ext.s, inf.gr = 2, sup.gr = 10,
                       criterion = "calinski")
clust.env
plot(clust.env)

plot(forest[, c("X", "Y")], pch=21, cex=1.2,
     bg=clust.env$partition[,5])
boxplot(ext$Altitude ~ clust.env$partition[,5],
        col=my.col)
