require(RODBC) require(vegan) require(labdsv) sws <- odbcConnect("swsartifex") # Tunnel to artifex port 3306 #A: all veg #O: open #T: tree #S: shrub # #Y: with trees #N: without trees # #C: canberra #J: jaccard #H: horn # # this script takes about 5 min ## RESINS vr <- sqlQuery(sws, "SELECT * FROM veg_resins_view") vr$cover[vr$cover == "willow"] <- "shrub" vrv <- vr[,c(5:129,134:138)] vrv$rando <- runif(length(vrv[,1]))*0.5 vrv.nt <- vrv vrv.nt$Abies_lasiocarpa <- vrv.nt$Picea_engelmannii <- vrv.nt$Salix_sp <- vrv.nt$Ribes_montigenum <- vrv.nt$Pinus_flexilis <- NULL vrv.nt$rando2 <- runif(length(vrv[,1]))*0.5 vrv.nt$Abies_lasiocarpa <- vrv.nt$Picea_engelmannii <- vrv.nt$Salix_sp <- vrv.nt$Ribes_montigenum <- vrv.nt$Pinus_flexilis <- NULL vr.ord <- data.frame(resin = vr[,1]) #all veg types WITH tree cover, but tree species united vrv.nt.canb <- vegdist(vrv.nt,'canberra') vrv.nt.canb.nmds <- nmds(vrv.nt.canb, k = 2) vr.ord$ANC2.1 <- vrv.nt.canb.nmds[[1]][,1] ; vr.ord$ANC2.2 <- vrv.nt.canb.nmds[[1]][,2] vrv.nt.jacc <- vegdist(vrv.nt,'jaccard') vrv.nt.jacc.nmds <- nmds(vrv.nt.jacc, k = 2) vr.ord$ANJ2.1 <- vrv.nt.jacc.nmds[[1]][,1] ; vr.ord$ANJ2.2 <- vrv.nt.jacc.nmds[[1]][,2] #all veg types WITHOUT tree cover vrv.nt.canb <- vegdist(vrv.nt,'canberra') vrv.nt.canb.nmds <- nmds(vrv.nt.canb, k = 5) vr.ord$ANC5.1 <- vrv.nt.canb.nmds[[1]][,1] ; vr.ord$ANC5.2 <- vrv.nt.canb.nmds[[1]][,2] vr.ord$ANC5.3 <- vrv.nt.canb.nmds[[1]][,3] ; vr.ord$ANC5.4 <- vrv.nt.canb.nmds[[1]][,4] vr.ord$ANC5.5 <- vrv.nt.canb.nmds[[1]][,5] vrv.nt.jacc <- vegdist(vrv.nt,'jaccard') vrv.nt.jacc.nmds <- nmds(vrv.nt.jacc, k = 5) vr.ord$ANJ5.1 <- vrv.nt.jacc.nmds[[1]][,1] ; vr.ord$ANJ5.2 <- vrv.nt.jacc.nmds[[1]][,2] vr.ord$ANJ5.3 <- vrv.nt.jacc.nmds[[1]][,3] ; vr.ord$ANJ5.4 <- vrv.nt.jacc.nmds[[1]][,4] vr.ord$ANJ5.5 <- vrv.nt.jacc.nmds[[1]][,5] #all veg types WITHOUT tree cover vrv.nt.canb <- vegdist(vrv.nt,'canberra') vrv.nt.canb.nmds <- nmds(vrv.nt.canb, k = 10) vr.ord$ANC10.1 <- vrv.nt.canb.nmds[[1]][,1] ; vr.ord$ANC10.2 <- vrv.nt.canb.nmds[[1]][,2] vr.ord$ANC10.3 <- vrv.nt.canb.nmds[[1]][,3] ; vr.ord$ANC10.4 <- vrv.nt.canb.nmds[[1]][,4] vr.ord$ANC10.5 <- vrv.nt.canb.nmds[[1]][,5] vr.ord$ANC10.6 <- vrv.nt.canb.nmds[[1]][,6] ; vr.ord$ANC10.7 <- vrv.nt.canb.nmds[[1]][,7] vr.ord$ANC10.8 <- vrv.nt.canb.nmds[[1]][,8] ; vr.ord$ANC10.9 <- vrv.nt.canb.nmds[[1]][,9] vr.ord$ANC10.10 <- vrv.nt.canb.nmds[[1]][,10] vrv.nt.jacc <- vegdist(vrv.nt,'jaccard') vrv.nt.jacc.nmds <- nmds(vrv.nt.jacc, k = 10) vr.ord$ANJ10.1 <- vrv.nt.jacc.nmds[[1]][,1] ; vr.ord$ANJ10.2 <- vrv.nt.jacc.nmds[[1]][,2] vr.ord$ANJ10.3 <- vrv.nt.jacc.nmds[[1]][,3] ; vr.ord$ANJ10.4 <- vrv.nt.jacc.nmds[[1]][,4] vr.ord$ANJ10.5 <- vrv.nt.jacc.nmds[[1]][,5] vr.ord$ANJ10.6 <- vrv.nt.canb.nmds[[1]][,6] ; vr.ord$ANJ10.7 <- vrv.nt.canb.nmds[[1]][,7] vr.ord$ANJ10.8 <- vrv.nt.canb.nmds[[1]][,8] ; vr.ord$ANJ10.9 <- vrv.nt.canb.nmds[[1]][,9] vr.ord$ANJ10.10 <- vrv.nt.canb.nmds[[1]][,10] ## SOILBINS vs <- sqlQuery(sws, "SELECT * FROM veg_soilbins_view") vsv <- vs[,c(5:123,128:132)] vsv$rando <- runif(length(vsv[,1]))*0.5 vsv.nt <- vsv vsv.nt$Abies_lasiocarpa <- vsv.nt$Picea_engelmannii <- vsv.nt$Salix_sp <- vsv.nt$Ribes_montigenum <- vsv.nt$Pinus_flexilis <- NULL vsv.nt$rando2 <- runif(length(vsv[,1]))*0.5 vs.ord <- data.frame(bin = vs[,1]) #all veg types WITHOUT tree cover vsv.nt.canb <- vegdist(vsv.nt,'canberra') vsv.nt.canb.nmds <- nmds(vsv.nt.canb, k = 2) vs.ord$ANC2.1 <- vsv.nt.canb.nmds[[1]][,1] ; vs.ord$ANC2.2 <- vsv.nt.canb.nmds[[1]][,2] vsv.nt.jacc <- vegdist(vsv.nt,'jaccard') vsv.nt.jacc.nmds <- nmds(vsv.nt.jacc, k = 2) vs.ord$ANJ2.1 <- vsv.nt.jacc.nmds[[1]][,1] ; vs.ord$ANJ2.2 <- vsv.nt.jacc.nmds[[1]][,2] #all veg types WITHOUT tree cover vsv.nt.canb <- vegdist(vsv.nt,'canberra') vsv.nt.canb.nmds <- nmds(vsv.nt.canb, k = 5) vs.ord$ANC5.1 <- vsv.nt.canb.nmds[[1]][,1] ; vs.ord$ANC5.2 <- vsv.nt.canb.nmds[[1]][,2] vs.ord$ANC5.3 <- vsv.nt.canb.nmds[[1]][,3] ; vs.ord$ANC5.4 <- vsv.nt.canb.nmds[[1]][,4] vs.ord$ANC5.5 <- vsv.nt.canb.nmds[[1]][,5] vsv.nt.jacc <- vegdist(vsv.nt,'jaccard') vsv.nt.jacc.nmds <- nmds(vsv.nt.jacc, k = 5) vs.ord$ANJ5.1 <- vsv.nt.jacc.nmds[[1]][,1] ; vs.ord$ANJ5.2 <- vsv.nt.jacc.nmds[[1]][,2] vs.ord$ANJ5.3 <- vsv.nt.jacc.nmds[[1]][,3] ; vs.ord$ANJ5.4 <- vsv.nt.jacc.nmds[[1]][,4] vs.ord$ANJ5.5 <- vsv.nt.jacc.nmds[[1]][,5] #all veg types WITHOUT tree cover vsv.nt.canb <- vegdist(vsv.nt,'canberra') vsv.nt.canb.nmds <- nmds(vsv.nt.canb, k = 10) vs.ord$ANC10.1 <- vsv.nt.canb.nmds[[1]][,1] ; vs.ord$ANC10.2 <- vsv.nt.canb.nmds[[1]][,2] vs.ord$ANC10.3 <- vsv.nt.canb.nmds[[1]][,3] ; vs.ord$ANC10.4 <- vsv.nt.canb.nmds[[1]][,4] vs.ord$ANC10.5 <- vsv.nt.canb.nmds[[1]][,5] vs.ord$ANC10.6 <- vsv.nt.canb.nmds[[1]][,6] ; vs.ord$ANC10.7 <- vsv.nt.canb.nmds[[1]][,7] vs.ord$ANC10.8 <- vsv.nt.canb.nmds[[1]][,8] ; vs.ord$ANC10.9 <- vsv.nt.canb.nmds[[1]][,9] vs.ord$ANC10.10 <- vsv.nt.canb.nmds[[1]][,10] vsv.nt.jacc <- vegdist(vsv.nt,'jaccard') vsv.nt.jacc.nmds <- nmds(vsv.nt.jacc, k = 10) vs.ord$ANJ10.1 <- vsv.nt.jacc.nmds[[1]][,1] ; vs.ord$ANJ10.2 <- vsv.nt.jacc.nmds[[1]][,2] vs.ord$ANJ10.3 <- vsv.nt.jacc.nmds[[1]][,3] ; vs.ord$ANJ10.4 <- vsv.nt.jacc.nmds[[1]][,4] vs.ord$ANJ10.5 <- vsv.nt.jacc.nmds[[1]][,5] vs.ord$ANJ10.6 <- vsv.nt.canb.nmds[[1]][,6] ; vs.ord$ANJ10.7 <- vsv.nt.canb.nmds[[1]][,7] vs.ord$ANJ10.8 <- vsv.nt.canb.nmds[[1]][,8] ; vs.ord$ANJ10.9 <- vsv.nt.canb.nmds[[1]][,9] vs.ord$ANJ10.10 <- vsv.nt.canb.nmds[[1]][,10] rm(vr, vrv, vrv.nt, vrv.nt.canb, vrv.nt.canb.nmds, vrv.nt.jacc, vrv.nt.jacc.nmds, vs, vsv, vsv.nt, vsv.nt.canb, vsv.nt.canb.nmds, vsv.nt.jacc, vsv.nt.jacc.nmds)