1
|
############
|
2
|
##Ordination
|
3
|
#data format: species matrix
|
4
|
require(vegan)
|
5
|
|
6
|
data.ord <- metaMDS(spp_matrix, dustance="bray", trace=TRUE)
|
7
|
|
8
|
#to extract x and y scores for plotting
|
9
|
ord.scores <- scores(data.ord, display=c("sites", "species"))
|
10
|
|
11
|
#adding year column to scores data.frame
|
12
|
year <- data.frame(spp_matrix$yearColumn)
|
13
|
colnames(year) <- "year"
|
14
|
|
15
|
ord.scores.yr <- cbind(ord.scores, year)
|
16
|
|
17
|
#plotting ordination
|
18
|
|
19
|
#setting graphical margins
|
20
|
par(mar=c(bottom, left, top, right), xpd=TRUE)
|
21
|
|
22
|
plot(data.ord, type = "n",
|
23
|
xlim = c(xMin, xMax), ylim = c(yMin, yMax))
|
24
|
|
25
|
points(ord.scores[c(1:25),], cex = 1.2, pch=16, col="#99CC66")
|
26
|
points(ord.scores[c(26:50),], cex = 1.2, pch=16, col="#990000")
|
27
|
|
28
|
#labeling points
|
29
|
require(calibrate)
|
30
|
|
31
|
textxy(ord.scores.yr$NMDS1, ord.scores.yr$NMDS2, ord.scores.yr$year)
|
32
|
|
33
|
#legend
|
34
|
leg.text <- c("x1", "x2")
|
35
|
leg.col <- c("#99CC66", "#990000")
|
36
|
legend(xAxisLocation, yAxisLocation, cex = 1.2, leg.text, col=leg.col, pch=16)
|