##########Introduction: 2. PERMANOVA tests (999 mutations) were done using adonis functions in the vegan package in R 3.2.3. Non-metric multidimensional scaling (NMDS) was used to visualize the pairwise Bray-Curtis distances among samples. ###----------Prepare your files------------- # read the files(the samples with OTUs and groups) you want to test ## Two files: 1. Your file with the OTUs or bacteria at some rank, should be a matrix file; 2. group file: the groups you prepare to analyse. perfield<- read.csv("C:\\Users\\xiaomiw1\\Desktop\\field.csv", header=TRUE, sep=",",row.names=1) grperfield<-read.csv("C:\\Users\\xiaomiw1\\Desktop\\field_group.csv", header=TRUE, sep=",",row.names=1) str(perfield) str(gperfield) ###----------PERMANOVA------------- pmv<-adonis(perfield^0.25~Group,data=grperfield,permutations=999,method="bray") #One group pmv<-adonis(per^0.25 ~ Year * Stage * Habitat, data = gper, permutations = 999, method = "bray") #Several models running ###------NMDS---------- ####-----Distance Matrix using Bray-Curtis on double-root transformed abundances range(perfield) distmatrix<-vegdist(perfield^0.25,method="bray") #Use a double-root transformation head(distmatrix) distmatrix nmds<-metaMDS(distmatrix) # Run NMDS plot(nmds) #you will get a scatter plot(nmds,type="text") #you will get a scatter only with names ### From here, Plot NMDS with your own preferences op<-ordiplot(nmds,type="n") #get an empty plot cols=c("Darkred","Darkgreen","Darkblue","Red","Green","Blue") #we can use a lot of colours based on your groups points(nmds,cex=2,pch=16,col=cols[grperfield$Group]) ## Group will be the groups that you divided the samples in ordispider(nmds,groups=grperfield$Group,label=FALSE) #connect all the samples to their own groups #label="TRUE" means that the groups names will be shown legend("topleft",pch=16,col=cols,legend=levels(grperfield$Group))