library(ade4)
library(gclus)
## Carregando pacotes exigidos: cluster
library(cluster)
library(RColorBrewer)
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.8     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ stringr 1.4.1
## ✔ readr   2.1.2     ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
load("C:/Users/vahum/AppData/Local/R/win-library/4.2/rmarkdown/rmarkdown/templates/github_document/NEwR-2ed_code_data/NEwR2-Data/Doubs.RData")
spe
##    Cogo Satr Phph Babl Thth Teso Chna Pato Lele Sqce Baba Albi Gogo Eslu Pefl
## 1     0    3    0    0    0    0    0    0    0    0    0    0    0    0    0
## 2     0    5    4    3    0    0    0    0    0    0    0    0    0    0    0
## 3     0    5    5    5    0    0    0    0    0    0    0    0    0    1    0
## 4     0    4    5    5    0    0    0    0    0    1    0    0    1    2    2
## 5     0    2    3    2    0    0    0    0    5    2    0    0    2    4    4
## 6     0    3    4    5    0    0    0    0    1    2    0    0    1    1    1
## 7     0    5    4    5    0    0    0    0    1    1    0    0    0    0    0
## 8     0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## 9     0    0    1    3    0    0    0    0    0    5    0    0    0    0    0
## 10    0    1    4    4    0    0    0    0    2    2    0    0    1    0    0
## 11    1    3    4    1    1    0    0    0    0    1    0    0    0    0    0
## 12    2    5    4    4    2    0    0    0    0    1    0    0    0    0    0
## 13    2    5    5    2    3    2    0    0    0    0    0    0    0    0    0
## 14    3    5    5    4    4    3    0    0    0    1    1    0    1    1    0
## 15    3    4    4    5    2    4    0    0    3    3    2    0    2    0    0
## 16    2    3    3    5    0    5    0    4    5    2    2    1    2    1    1
## 17    1    2    4    4    1    2    1    4    3    2    3    4    1    1    2
## 18    1    1    3    3    1    1    1    3    2    3    3    3    2    1    3
## 19    0    0    3    5    0    1    2    3    2    1    2    2    4    1    1
## 20    0    0    1    2    0    0    2    2    2    3    4    3    4    2    2
## 21    0    0    1    1    0    0    2    2    2    2    4    2    5    3    3
## 22    0    0    0    1    0    0    3    2    3    4    5    1    5    3    4
## 23    0    0    0    0    0    0    0    0    0    1    0    0    0    0    0
## 24    0    0    0    0    0    0    1    0    0    2    0    0    1    0    0
## 25    0    0    0    0    0    0    0    0    1    1    0    0    2    1    0
## 26    0    0    0    1    0    0    1    0    1    2    2    1    3    2    1
## 27    0    0    0    1    0    0    1    1    2    3    4    1    4    4    1
## 28    0    0    0    1    0    0    1    1    2    4    3    1    4    3    2
## 29    0    1    1    1    1    1    2    2    3    4    5    3    5    5    4
## 30    0    0    0    0    0    0    1    2    3    3    3    5    5    4    5
##    Rham Legi Scer Cyca Titi Abbr Icme Gyce Ruru Blbj Alal Anan
## 1     0    0    0    0    0    0    0    0    0    0    0    0
## 2     0    0    0    0    0    0    0    0    0    0    0    0
## 3     0    0    0    0    0    0    0    0    0    0    0    0
## 4     0    0    0    0    1    0    0    0    0    0    0    0
## 5     0    0    2    0    3    0    0    0    5    0    0    0
## 6     0    0    0    0    2    0    0    0    1    0    0    0
## 7     0    0    0    0    0    0    0    0    0    0    0    0
## 8     0    0    0    0    0    0    0    0    0    0    0    0
## 9     0    0    0    0    1    0    0    0    4    0    0    0
## 10    0    0    0    0    0    0    0    0    0    0    0    0
## 11    0    0    0    0    0    0    0    0    0    0    0    0
## 12    0    0    0    0    0    0    0    0    0    0    0    0
## 13    0    0    0    0    0    0    0    0    0    0    0    0
## 14    0    0    0    0    0    0    0    0    0    0    0    0
## 15    0    0    0    0    1    0    0    0    0    0    0    0
## 16    0    1    0    1    1    0    0    0    1    0    0    0
## 17    1    1    0    1    1    0    0    0    2    0    2    1
## 18    2    1    0    1    1    0    0    1    2    0    2    1
## 19    2    1    1    1    2    1    0    1    5    1    3    1
## 20    3    2    2    1    4    1    0    2    5    2    5    2
## 21    3    2    2    2    4    3    1    3    5    3    5    2
## 22    3    3    2    3    4    4    2    4    5    4    5    2
## 23    0    0    0    0    0    0    0    0    1    0    2    0
## 24    0    1    0    0    0    0    0    2    2    1    5    0
## 25    0    0    1    0    0    0    0    1    1    0    3    0
## 26    2    2    1    1    3    2    1    4    4    2    5    2
## 27    3    3    1    2    5    3    2    5    5    4    5    3
## 28    4    4    2    4    4    3    3    5    5    5    5    4
## 29    5    5    2    3    3    4    4    5    5    4    5    4
## 30    5    3    5    5    5    5    5    5    5    5    5    5
env
##      dfs ele  slo   dis  pH har  pho  nit  amm  oxy  bod
## 1    0.3 934 48.0  0.84 7.9  45 0.01 0.20 0.00 12.2  2.7
## 2    2.2 932  3.0  1.00 8.0  40 0.02 0.20 0.10 10.3  1.9
## 3   10.2 914  3.7  1.80 8.3  52 0.05 0.22 0.05 10.5  3.5
## 4   18.5 854  3.2  2.53 8.0  72 0.10 0.21 0.00 11.0  1.3
## 5   21.5 849  2.3  2.64 8.1  84 0.38 0.52 0.20  8.0  6.2
## 6   32.4 846  3.2  2.86 7.9  60 0.20 0.15 0.00 10.2  5.3
## 7   36.8 841  6.6  4.00 8.1  88 0.07 0.15 0.00 11.1  2.2
## 8   49.1 792  2.5  1.30 8.1  94 0.20 0.41 0.12  7.0  8.1
## 9   70.5 752  1.2  4.80 8.0  90 0.30 0.82 0.12  7.2  5.2
## 10  99.0 617  9.9 10.00 7.7  82 0.06 0.75 0.01 10.0  4.3
## 11 123.4 483  4.1 19.90 8.1  96 0.30 1.60 0.00 11.5  2.7
## 12 132.4 477  1.6 20.00 7.9  86 0.04 0.50 0.00 12.2  3.0
## 13 143.6 450  2.1 21.10 8.1  98 0.06 0.52 0.00 12.4  2.4
## 14 152.2 434  1.2 21.20 8.3  98 0.27 1.23 0.00 12.3  3.8
## 15 164.5 415  0.5 23.00 8.6  86 0.40 1.00 0.00 11.7  2.1
## 16 185.9 375  2.0 16.10 8.0  88 0.20 2.00 0.05 10.3  2.7
## 17 198.5 349  0.5 24.30 8.0  92 0.20 2.50 0.20 10.2  4.6
## 18 211.0 333  0.8 25.00 8.0  90 0.50 2.20 0.20 10.3  2.8
## 19 224.6 310  0.5 25.90 8.1  84 0.60 2.20 0.15 10.6  3.3
## 20 247.7 286  0.8 26.80 8.0  86 0.30 3.00 0.30 10.3  2.8
## 21 282.1 262  1.0 27.20 7.9  85 0.20 2.20 0.10  9.0  4.1
## 22 294.0 254  1.4 27.90 8.1  88 0.20 1.62 0.07  9.1  4.8
## 23 304.3 246  1.2 28.80 8.1  97 2.60 3.50 1.15  6.3 16.4
## 24 314.7 241  0.3 29.76 8.0  99 1.40 2.50 0.60  5.2 12.3
## 25 327.8 231  0.5 38.70 7.9 100 4.22 6.20 1.80  4.1 16.7
## 26 356.9 214  0.5 39.10 7.9  94 1.43 3.00 0.30  6.2  8.9
## 27 373.2 206  1.2 39.60 8.1  90 0.58 3.00 0.26  7.2  6.3
## 28 394.7 195  0.3 43.20 8.3 100 0.74 4.00 0.30  8.1  4.5
## 29 422.0 183  0.6 67.70 7.8 110 0.45 1.62 0.10  9.0  4.2
## 30 453.0 172  0.2 69.00 8.2 109 0.65 1.60 0.10  8.2  4.4
spa
##          X       Y
## 1   85.678  20.000
## 2   84.955  20.100
## 3   92.301  23.796
## 4   91.280  26.431
## 5   92.005  29.163
## 6   95.954  36.315
## 7   98.201  38.799
## 8   99.455  46.406
## 9  109.782  55.865
## 10 130.641  66.576
## 11 142.748  81.258
## 12 147.270  85.839
## 13 156.817  89.516
## 14 159.435  92.791
## 15 150.820  91.084
## 16 132.662  87.956
## 17 128.298  93.918
## 18 130.560 102.446
## 19 128.459 105.428
## 20 114.862 103.129
## 21  97.163  90.245
## 22  88.200  86.373
## 23  79.596  83.508
## 24  74.753  78.734
## 25  67.146  74.683
## 26  53.770  71.598
## 27  43.637  68.673
## 28  30.514  61.166
## 29  20.495  43.848
## 30   0.000  41.562

1)Use a base “spe” e tente econtrar grupos de amostras (comunidades) que pertencem à trechos específicos do rio

k3<-kmeans(spe, centers = 3, nstart=25)
k3
## K-means clustering with 3 clusters of sizes 12, 8, 10
## 
## Cluster means:
##       Cogo  Satr  Phph Babl  Thth     Teso  Chna      Pato Lele     Sqce
## 1 1.083333 4.000 4.250  4.0 1.000 1.166667 0.000 0.3333333 1.00 1.166667
## 2 0.000000 0.125 0.375  1.0 0.125 0.125000 1.625 1.5000000 2.25 3.125000
## 3 0.200000 0.800 1.400  1.7 0.200 0.400000 0.500 1.0000000 1.30 1.700000
##        Baba       Albi      Gogo Eslu      Pefl Rham       Legi  Scer
## 1 0.4166667 0.08333333 0.6666667 0.50 0.3333333  0.0 0.08333333 0.000
## 2 3.7500000 2.12500000 4.3750000 3.25 2.7500000  3.5 3.00000000 2.125
## 3 0.8000000 0.90000000 1.2000000 0.80 1.0000000  0.5 0.40000000 0.400
##         Cyca      Titi  Abbr Icme  Gyce      Ruru  Blbj Alal Anan
## 1 0.08333333 0.4166667 0.000 0.00 0.000 0.1666667 0.000  0.0  0.0
## 2 2.62500000 4.0000000 3.125 2.25 4.125 4.8750000 3.625  5.0  3.0
## 3 0.30000000 0.8000000 0.100 0.00 0.500 2.2000000 0.200  1.7  0.3
## 
## Clustering vector:
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
##  3  1  1  1  3  1  1  3  3  1  1  1  1  1  1  1  3  3  3  2  2  2  3  3  3  2 
## 27 28 29 30 
##  2  2  2  2 
## 
## Within cluster sum of squares by cluster:
## [1] 203.75 176.75 329.90
##  (between_SS / total_SS =  64.2 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"

2)teste tanto medidas de distância quanto métodos de agrupamento diferentes

Aglomerativo

spe
##    Cogo Satr Phph Babl Thth Teso Chna Pato Lele Sqce Baba Albi Gogo Eslu Pefl
## 1     0    3    0    0    0    0    0    0    0    0    0    0    0    0    0
## 2     0    5    4    3    0    0    0    0    0    0    0    0    0    0    0
## 3     0    5    5    5    0    0    0    0    0    0    0    0    0    1    0
## 4     0    4    5    5    0    0    0    0    0    1    0    0    1    2    2
## 5     0    2    3    2    0    0    0    0    5    2    0    0    2    4    4
## 6     0    3    4    5    0    0    0    0    1    2    0    0    1    1    1
## 7     0    5    4    5    0    0    0    0    1    1    0    0    0    0    0
## 8     0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## 9     0    0    1    3    0    0    0    0    0    5    0    0    0    0    0
## 10    0    1    4    4    0    0    0    0    2    2    0    0    1    0    0
## 11    1    3    4    1    1    0    0    0    0    1    0    0    0    0    0
## 12    2    5    4    4    2    0    0    0    0    1    0    0    0    0    0
## 13    2    5    5    2    3    2    0    0    0    0    0    0    0    0    0
## 14    3    5    5    4    4    3    0    0    0    1    1    0    1    1    0
## 15    3    4    4    5    2    4    0    0    3    3    2    0    2    0    0
## 16    2    3    3    5    0    5    0    4    5    2    2    1    2    1    1
## 17    1    2    4    4    1    2    1    4    3    2    3    4    1    1    2
## 18    1    1    3    3    1    1    1    3    2    3    3    3    2    1    3
## 19    0    0    3    5    0    1    2    3    2    1    2    2    4    1    1
## 20    0    0    1    2    0    0    2    2    2    3    4    3    4    2    2
## 21    0    0    1    1    0    0    2    2    2    2    4    2    5    3    3
## 22    0    0    0    1    0    0    3    2    3    4    5    1    5    3    4
## 23    0    0    0    0    0    0    0    0    0    1    0    0    0    0    0
## 24    0    0    0    0    0    0    1    0    0    2    0    0    1    0    0
## 25    0    0    0    0    0    0    0    0    1    1    0    0    2    1    0
## 26    0    0    0    1    0    0    1    0    1    2    2    1    3    2    1
## 27    0    0    0    1    0    0    1    1    2    3    4    1    4    4    1
## 28    0    0    0    1    0    0    1    1    2    4    3    1    4    3    2
## 29    0    1    1    1    1    1    2    2    3    4    5    3    5    5    4
## 30    0    0    0    0    0    0    1    2    3    3    3    5    5    4    5
##    Rham Legi Scer Cyca Titi Abbr Icme Gyce Ruru Blbj Alal Anan
## 1     0    0    0    0    0    0    0    0    0    0    0    0
## 2     0    0    0    0    0    0    0    0    0    0    0    0
## 3     0    0    0    0    0    0    0    0    0    0    0    0
## 4     0    0    0    0    1    0    0    0    0    0    0    0
## 5     0    0    2    0    3    0    0    0    5    0    0    0
## 6     0    0    0    0    2    0    0    0    1    0    0    0
## 7     0    0    0    0    0    0    0    0    0    0    0    0
## 8     0    0    0    0    0    0    0    0    0    0    0    0
## 9     0    0    0    0    1    0    0    0    4    0    0    0
## 10    0    0    0    0    0    0    0    0    0    0    0    0
## 11    0    0    0    0    0    0    0    0    0    0    0    0
## 12    0    0    0    0    0    0    0    0    0    0    0    0
## 13    0    0    0    0    0    0    0    0    0    0    0    0
## 14    0    0    0    0    0    0    0    0    0    0    0    0
## 15    0    0    0    0    1    0    0    0    0    0    0    0
## 16    0    1    0    1    1    0    0    0    1    0    0    0
## 17    1    1    0    1    1    0    0    0    2    0    2    1
## 18    2    1    0    1    1    0    0    1    2    0    2    1
## 19    2    1    1    1    2    1    0    1    5    1    3    1
## 20    3    2    2    1    4    1    0    2    5    2    5    2
## 21    3    2    2    2    4    3    1    3    5    3    5    2
## 22    3    3    2    3    4    4    2    4    5    4    5    2
## 23    0    0    0    0    0    0    0    0    1    0    2    0
## 24    0    1    0    0    0    0    0    2    2    1    5    0
## 25    0    0    1    0    0    0    0    1    1    0    3    0
## 26    2    2    1    1    3    2    1    4    4    2    5    2
## 27    3    3    1    2    5    3    2    5    5    4    5    3
## 28    4    4    2    4    4    3    3    5    5    5    5    4
## 29    5    5    2    3    3    4    4    5    5    4    5    4
## 30    5    3    5    5    5    5    5    5    5    5    5    5
df <- spe
df <- na.omit(df)
df <- scale(df)
head(df)
##         Cogo       Satr       Phph       Babl       Thth      Teso       Chna
## 1 -0.5332108 0.53918531 -1.1439008 -1.2646370 -0.4957446 -0.487395 -0.7017498
## 2 -0.5332108 1.51952223  0.8747476  0.2945045 -0.4957446 -0.487395 -0.7017498
## 3 -0.5332108 1.51952223  1.3794098  1.3339321 -0.4957446 -0.487395 -0.7017498
## 4 -0.5332108 1.02935377  1.3794098  1.3339321 -0.4957446 -0.487395 -0.7017498
## 5 -0.5332108 0.04901685  0.3700855 -0.2252093 -0.4957446 -0.487395 -0.7017498
## 6 -0.5332108 0.53918531  0.8747476  1.3339321 -0.4957446 -0.487395 -0.7017498
##         Pato       Lele        Sqce       Baba       Albi        Gogo
## 1 -0.6635823 -0.9547024 -1.37475155 -0.8165042 -0.6436503 -0.99645665
## 2 -0.6635823 -0.9547024 -1.37475155 -0.8165042 -0.6436503 -0.99645665
## 3 -0.6635823 -0.9547024 -1.37475155 -0.8165042 -0.6436503 -0.99645665
## 4 -0.6635823 -0.9547024 -0.63827750 -0.8165042 -0.6436503 -0.45293484
## 5 -0.6635823  2.3756549  0.09819654 -0.8165042 -0.6436503  0.09058697
## 6 -0.6635823 -0.2886310  0.09819654 -0.8165042 -0.6436503 -0.45293484
##         Eslu       Pefl       Rham       Legi       Scer       Cyca       Titi
## 1 -0.8793937 -0.7790871 -0.6677353 -0.6897081 -0.6091127 -0.6213284 -0.8635475
## 2 -0.8793937 -0.7790871 -0.6677353 -0.6897081 -0.6091127 -0.6213284 -0.8635475
## 3 -0.2198484 -0.7790871 -0.6677353 -0.6897081 -0.6091127 -0.6213284 -0.8635475
## 4  0.4396969  0.5193914 -0.6677353 -0.6897081 -0.6091127 -0.6213284 -0.2878492
## 5  1.7587875  1.8178700 -0.6677353 -0.6897081  1.1312093 -0.6213284  0.8635475
## 6 -0.2198484 -0.1298479 -0.6677353 -0.6897081 -0.6091127 -0.6213284  0.2878492
##         Abbr       Icme       Gyce       Ruru       Blbj       Alal       Anan
## 1 -0.5682069 -0.4606464 -0.6693037 -0.9533914 -0.6036916 -0.8447682 -0.6220813
## 2 -0.5682069 -0.4606464 -0.6693037 -0.9533914 -0.6036916 -0.8447682 -0.6220813
## 3 -0.5682069 -0.4606464 -0.6693037 -0.9533914 -0.6036916 -0.8447682 -0.6220813
## 4 -0.5682069 -0.4606464 -0.6693037 -0.9533914 -0.6036916 -0.8447682 -0.6220813
## 5 -0.5682069 -0.4606464 -0.6693037  1.3165882 -0.6036916 -0.8447682 -0.6220813
## 6 -0.5682069 -0.4606464 -0.6693037 -0.4993955 -0.6036916 -0.8447682 -0.6220813
d <- dist(df, method = "euclidean")
hc1 <- hclust(d, method = "complete" )
plot(hc1, cex = 0.6, hang = -1)

grup_spe<-cutree(hc1, k=12)
table(grup_spe)
## grup_spe
##  1  2  3  4  5  6  7  8  9 10 11 12 
##  5  7  1  1  3  1  1  3  3  3  1  1
plot(hc1)
rect.hclust(hc1, k = 12, border = 2:12)

Divisivo

hc4 <- diana(df)
hc4$dc
## [1] 0.792261
pltree(hc4, cex = 0.6, hang = -1, main = "Dendrogram of diana")

grup_spee<-cutree(hc4, k=6)
table(grup_spee)
## grup_spee
##  1  2  3  4  5  6 
## 13  1  3  5  6  2
plot(hc4)

rect.hclust(hc4, k = 6, border = 2:6)

3)Use métodos de K-means para encontrar quantos clusters há de fato segundo o método “silhouette”

fviz_cluster(k3, data = spe)

fviz_nbclust(spe, kmeans, method = "silhouette")

k2<-kmeans(spe, centers =2, nstart=25)
fviz_cluster(k2, data = spe)

4)Garafique o rio colorindo as amostras segundo seu pertencimento aos clusters gerados como esse aqui

k2<-kmeans(spa, centers = 2, nstart=25)
k2
## K-means clustering with 2 clusters of sizes 18, 12
## 
## Cluster means:
##           X        Y
## 1  72.65122 50.39000
## 2 134.97792 90.84883
## 
## Clustering vector:
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
##  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2  2  2  2  2  1  1  1  1  1 
## 27 28 29 30 
##  1  1  1  1 
## 
## Within cluster sum of squares by cluster:
## [1] 24776.02  4730.82
##  (between_SS / total_SS =  57.4 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
fviz_cluster(k2, data = spa)

5)Avalie com gráficos de boxplot como os clusters são diferenciados em termos ambientais (base “env”) e comente os resltados brevemente, tentando interpretar os resultados biológicos.

e2<-kmeans(env[,-c(1,2,3,4,6,8,9,12)], centers = 2, nstart=25)
e2
## K-means clustering with 2 clusters of sizes 4, 26
## 
## Cluster means:
##         pH       pho      oxy       bod
## 1 7.975000 2.4125000 5.450000 13.575000
## 2 8.061538 0.2723077 9.996154  3.815385
## 
## Clustering vector:
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
##  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  1  1  1  1 
## 27 28 29 30 
##  2  2  2  2 
## 
## Within cluster sum of squares by cluster:
## [1]  49.71767 130.97006
##  (between_SS / total_SS =  69.8 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
fviz_cluster(e2, data = env[,-c(1,2,3,4,6,8,9,12)])

As características ph, pho, oxy e bod levam a clara separaçõa de 2 áreas no rio.

e3<-kmeans(env[,-c(1,4,5,7,10,11,12)], centers = 3, nstart=25)
e3
## K-means clustering with 3 clusters of sizes 14, 9, 7
## 
## Cluster means:
##        ele      slo      har      nit         amm
## 1 248.7143 0.700000 94.57143 2.795714 0.402142857
## 2 857.1111 8.188889 69.44444 0.320000 0.065555556
## 3 464.4286 3.057143 90.57143 1.085714 0.008571429
## 
## Clustering vector:
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
##  2  2  2  2  2  2  2  2  2  3  3  3  3  3  3  3  1  1  1  1  1  1  1  1  1  1 
## 27 28 29 30 
##  1  1  1  1 
## 
## Within cluster sum of squares by cluster:
## [1] 39934.35 35749.75 35681.39
##  (between_SS / total_SS =  94.8 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
fviz_cluster(e3, data = env[,-c(1,4,5,7,10,11,12)])

O gráfico está meio confuso portanto irei confirmar se 3 é o melhor número de clusters para separar.

fviz_nbclust(env[,-c(1,4,5,7,10,11,12)], kmeans, method = "silhouette")

O resultado mostra que 2 clusters é a melhor opção para esses dados.

e2.2<-kmeans(env[,-c(1,4,5,7,10,11,12)], centers = 2, nstart=25)
e2.2
## K-means clustering with 2 clusters of sizes 10, 20
## 
## Cluster means:
##     ele   slo  har    nit   amm
## 1 833.1 8.360 70.7 0.3630 0.060
## 2 305.8 1.065 93.8 2.2995 0.284
## 
## Clustering vector:
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
##  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2 
## 27 28 29 30 
##  2  2  2  2 
## 
## Within cluster sum of squares by cluster:
## [1]  87782.44 200440.03
##  (between_SS / total_SS =  86.6 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"
fviz_cluster(e2.2, data = env[,-c(1,4,5,7,10,11,12)])

Portanto, as caracteristica ele, slo, har, nit, e amn geraram um melhor resultado com 2 clusters,e consquentemente, mostra a relação entre os dados biologicos analisados no primeiro e segundo gráfico.