###DISSIMILARITY MATRICES + MANTEL CORRELATION---------------------- ##import data spe <- read.delim("forest_JMK_species.txt", header=T, row.names=1) #standardize to presence/absence data #library(vegan) spe.pa <- decostand(spe, "pa") spe.pa[1:10,1:10] #calculate dissimilarity matrices beta.j <- vegdist(spe.pa, method = "jaccard") head(beta.j) class(beta.j) #convert to matrix beta.j.mat <- as.matrix(beta.j) beta.j.mat[1:5,1:5] betadiver(help=TRUE) beta.b <- betadiver(spe.pa, method = "sim") #calculate environmental and geographical distances coord <- forest[, c("X", "Y")] geodist <- dist(coord, method = "euclidean") envdist <- dist(env.tab.s, method = "euclidean") #mantel correlation m.geo <- mantel(beta.b, geodist, permutations=499) m.env <- mantel(beta.b, envdist, permutations=499) #plot relationship plot(geodist, beta.b) plot(envdist, beta.b) plot.data <- cbind(envdist, beta.b) plot(plot.data, col = densCols(plot.data, colramp = colorRampPalette(c("gray90", "gray10"))))