# PCoA(MDS) vs. NMDS
###### tags: `R教學` `多變量分析`
```r=
library("vegan")
pcoa <- cmdscale (eurodist, eig = TRUE)
library (vegan)
ordiplot (pcoa, display = 'sites', type = 'text')
pcoa[,2] <- -pcoa[,2]
ordiplot (pcoa, display = 'sites', type = 't')
barplot (pcoa$eig, names = paste ('PCoA', 1:21), las = 3, ylab = 'eigenvalues')
library (vegan)
morse.dist <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/morsecodes-dist.txt', row.names = 1, head = T)
names (morse.dist) <- rownames (morse.dist)
NMDS <- metaMDS (morse.dist)
NMDS
par (mfrow = c(1,2))
ordiplot (NMDS, cex = 1.5, type = 't')
stressplot (NMDS)
morse.attr <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/morsecodes-attr.txt', row.names = 1, head = T)
ef <- envfit (NMDS, morse.attr)
ordiplot (NMDS, cex = 1.5, type = 't')
plot (ef)
vltava.spe <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/vltava-spe.txt', row.names = 1)
NMDS <- metaMDS (vltava.spe)
ordiplot (NMDS, type = 't')
par (mfrow = c(1,2)) # this function divides plotting window into two columns
stressplot (NMDS)
plot (NMDS, display = 'sites', type = 't', main = 'Goodness of fit') # this function draws NMDS ordination diagram with sites
points (NMDS, display = 'sites', cex = goodness (NMDS)*200) # and this adds the points with size reflecting goodness of fit (bigger = worse fit)
```