Analisis NMDS merupakan metode visualisasi dari pengelompokan lokasi berdasarkan kesamaan kelimpahan dan komposisi spesies. Kesamaan lokasi dapat dianalisis menggunakan analysis of similarities (ANOSIM). Cara melakukan ANOSIM dapat dilihat di sini

Memuat Paket

Memuat paket tambahan yang digunakan.

library(vegan)
library(ggplot2)
library(ggforce)
library(RColorBrewer)

Memuat dan Manipulasi Data

# memuat data
dm <- read.csv("data ekologi.csv")
head(dm)
##    site  env1  env2 env3 env4 env5 sp.1 sp.2 sp.3 sp.4 sp.5 sp.6 sp.7 sp.8 sp.9
## 1 site1 27.71 34.17 7.78  5.4  6.7   19    2    0    0    0   12    0    0    0
## 2 site2 28.37 34.07 7.78  5.5  5.6    3    1    0    0    0   19    0    1    0
## 3 site3 29.81 34.32 7.80  4.9  7.1    6    0    1    0    0   11    1    0    0
## 4 site4 27.27 34.37 7.84  5.0  5.5    5    0    0    0    0    0    0    0    1
## 5 site5 28.42 34.01 7.79  5.2  6.9    1    4    0    1    0    2    2    0    0
## 6 site1 29.97 33.77 7.71  5.0  6.3   30    4    0    0    0   14    0    0    0
##   sp.10 sp.11 sp.12
## 1     0     0     8
## 2     2     0     0
## 3     0     9    14
## 4     0     0     0
## 5     0     0     0
## 6     8     0     5
# mengambil bagian tertentu data (indeksing)
dm.bio <- dm[,7:ncol(dm)] #data biologi
head(dm.bio)
##   sp.1 sp.2 sp.3 sp.4 sp.5 sp.6 sp.7 sp.8 sp.9 sp.10 sp.11 sp.12
## 1   19    2    0    0    0   12    0    0    0     0     0     8
## 2    3    1    0    0    0   19    0    1    0     2     0     0
## 3    6    0    1    0    0   11    1    0    0     0     9    14
## 4    5    0    0    0    0    0    0    0    1     0     0     0
## 5    1    4    0    1    0    2    2    0    0     0     0     0
## 6   30    4    0    0    0   14    0    0    0     8     0     5
dm.env <- dm[,2:6] #data lingkungan
head(dm.env)
##    env1  env2 env3 env4 env5
## 1 27.71 34.17 7.78  5.4  6.7
## 2 28.37 34.07 7.78  5.5  5.6
## 3 29.81 34.32 7.80  4.9  7.1
## 4 27.27 34.37 7.84  5.0  5.5
## 5 28.42 34.01 7.79  5.2  6.9
## 6 29.97 33.77 7.71  5.0  6.3
# transformasi data biologi
dm.bio.hel <- decostand(dm.bio, method = "hellinger") #Hellinger transformasi
m_bio.hel <- as.matrix(dm.bio.hel) #ubah ke bentuk matriks

Ordinasi NMDS

set.seed(123)
nmds <- metaMDS(m_bio.hel, distance = "bray") #menggunakan jarak Bray-Curtis (Bray-Curtis dissimilarities)
## Run 0 stress 0.1425044 
## Run 1 stress 0.1494743 
## Run 2 stress 0.1425045 
## ... Procrustes: rmse 0.0002803509  max resid 0.0006143625 
## ... Similar to previous best
## Run 3 stress 0.1362647 
## ... New best solution
## ... Procrustes: rmse 0.08505289  max resid 0.2488048 
## Run 4 stress 0.1628323 
## Run 5 stress 0.1362647 
## ... New best solution
## ... Procrustes: rmse 3.120699e-05  max resid 6.953993e-05 
## ... Similar to previous best
## Run 6 stress 0.1425045 
## Run 7 stress 0.1673629 
## Run 8 stress 0.1682392 
## Run 9 stress 0.1425044 
## Run 10 stress 0.1362647 
## ... Procrustes: rmse 4.054531e-05  max resid 8.855762e-05 
## ... Similar to previous best
## Run 11 stress 0.1507346 
## Run 12 stress 0.1515718 
## Run 13 stress 0.1459451 
## Run 14 stress 0.1879625 
## Run 15 stress 0.1362647 
## ... Procrustes: rmse 5.787332e-07  max resid 1.217762e-06 
## ... Similar to previous best
## Run 16 stress 0.1425044 
## Run 17 stress 0.1697987 
## Run 18 stress 0.1459451 
## Run 19 stress 0.1507346 
## Run 20 stress 0.1483961 
## *** Best solution repeated 3 times
# print hasil analisis
nmds
## 
## Call:
## metaMDS(comm = m_bio.hel, distance = "bray") 
## 
## global Multidimensional Scaling using monoMDS
## 
## Data:     m_bio.hel 
## Distance: bray 
## 
## Dimensions: 2 
## Stress:     0.1362647 
## Stress type 1, weak ties
## Best solution was repeated 3 times in 20 tries
## The best solution was from try 5 (random start)
## Scaling: centring, PC rotation, halfchange scaling 
## Species: expanded scores based on 'm_bio.hel'
scores(nmds)
## $sites
##          NMDS1        NMDS2
## 1  -0.05673274  0.102369481
## 2   0.25971164 -0.453724581
## 3   0.21247412  0.486711311
## 4  -1.05793691  0.000365098
## 5   0.77829219  0.052089766
## 6  -0.10320831 -0.128455769
## 7   0.01811721  0.331907961
## 8   0.09809488 -0.211070804
## 9  -0.87538744  0.240802719
## 10  0.76333079  0.102235255
## 11 -0.28448890  0.154244954
## 12  0.35802732 -0.420520778
## 13 -0.31753666 -0.590553262
## 14 -0.28224649  0.054564156
## 15  0.48948930  0.279034492
## 
## $species
##             NMDS1       NMDS2
## sp.1  -0.33619453  0.07045321
## sp.2   0.71553979  0.08465525
## sp.3  -0.02846176 -0.28694764
## sp.4   1.04781306  0.29134762
## sp.5  -0.29690714 -0.28201333
## sp.6   0.18127889 -0.12391126
## sp.7   0.98714619  0.33387161
## sp.8   0.44940359 -0.86534716
## sp.9  -1.20809916 -0.53690714
## sp.10 -0.24455232 -0.83348011
## sp.11  0.21618738  0.68889803
## sp.12  0.12053865  0.30386768

Visualisasi

# ekstrak skor NMDS (koordinate x and y)
data.scores <- as.data.frame(scores(nmds)$sites)
data.scores$lokasi <- dm$site
head(data.scores)

# Menambahkan skor untuk data spesies
species.scores <- as.data.frame(scores(nmds, "species"))

# Menambahkan kolom untuk label spesies
species.scores$spesies <- rownames(species.scores)

# warna untuk plot
display.brewer.all(colorblindFriendly = TRUE)

# plot
ggplot(data = data.scores, aes(x = NMDS1,y = NMDS2)) +
  geom_text(data = species.scores, aes(label = spesies), alpha = 0.7,
            size = 3.5, nudge_x = -.2, nudge_y = 0.1, check_overlap = F) + #teks spesies
  geom_point(data = data.scores, aes(colour = lokasi), size = 2.5,
             alpha = 0.95) + #titik lokasi
  scale_color_brewer(palette = "Dark2") + #warna plot
  annotate(geom = "label", x = -1.2, y = 1.0, size = 3.5,
           label = paste("Stress value: ", round(nmds$stress, digits = 3))) + #stress value
  geom_mark_ellipse(aes(color = lokasi), alpha = 0.1) +
  coord_fixed(xlim = c(-1.5,1), ylim = c(-1,1)) + #penentuan koordinat
  theme(axis.text.y = element_text(colour = "black", size = 10,
                                   face = "bold", family = "serif"), 
        axis.text.x = element_text(colour = "black", face = "bold",
                                   size = 10, family = "serif"), 
        legend.text = element_text(size = 10, face = "bold",
                                   colour ="black", family = "serif"), 
        legend.position = "right",
        axis.title.y = element_text(face = "bold", size = 14, family = "serif"), 
        axis.title.x = element_text(face = "bold", size = 14,
                                    colour = "black", family = "serif"), 
        legend.title = element_text(size = 14, colour = "black",
                                    face = "bold", family="serif"), 
        panel.background = element_blank(),
        panel.border = element_rect(colour = "black", fill = NA, linewidth = 1.2),
        legend.key = element_blank()) +
  labs(x = "NMDS1", y = "NMDS2", color = "Lokasi")

Berdasarkan plot, antara satu lokasi satu dengan lainnya masih saling silang, hanya site5 yang tidak menyilang lokasi lain. Artinya pengelompokkan belum terpisah sepenuhnya.

# menyimpan plot
ggsave(filename = "NMDS.tiff", path = "C:/Users/ahmad/OneDrive/R Documents",
       width = 7, height = 5, dpi=600) #simpan dalam format tiff

Session Info:

## R version 4.3.2 (2023-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19045)
## 
## Matrix products: default
## 
## 
## locale:
## [1] LC_COLLATE=English_United States.utf8 
## [2] LC_CTYPE=English_United States.utf8   
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.utf8    
## 
## time zone: Asia/Jakarta
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] RColorBrewer_1.1-3 ggforce_0.4.2      ggplot2_3.5.0      vegan_2.6-4       
## [5] lattice_0.21-9     permute_0.9-7     
## 
## loaded via a namespace (and not attached):
##  [1] Matrix_1.6-5      gtable_0.3.4      jsonlite_1.8.8    highr_0.10       
##  [5] dplyr_1.1.4       compiler_4.3.2    Rcpp_1.0.12       tidyselect_1.2.0 
##  [9] parallel_4.3.2    cluster_2.1.4     jquerylib_0.1.4   splines_4.3.2    
## [13] scales_1.3.0      yaml_2.3.8        fastmap_1.1.1     R6_2.5.1         
## [17] labeling_0.4.3    generics_0.1.3    knitr_1.45        MASS_7.3-60      
## [21] polyclip_1.10-6   tibble_3.2.1      munsell_0.5.0     bslib_0.6.1      
## [25] pillar_1.9.0      rlang_1.1.3       utf8_1.2.4        cachem_1.0.8     
## [29] xfun_0.42         sass_0.4.8        cli_3.6.2         tweenr_2.0.3     
## [33] withr_3.0.0       magrittr_2.0.3    mgcv_1.9-0        digest_0.6.34    
## [37] grid_4.3.2        rstudioapi_0.15.0 lifecycle_1.0.4   nlme_3.1-163     
## [41] vctrs_0.6.5       evaluate_0.23     glue_1.7.0        farver_2.1.1     
## [45] fansi_1.0.6       colorspace_2.1-0  rmarkdown_2.25    tools_4.3.2      
## [49] pkgconfig_2.0.3   htmltools_0.5.7