library(vegan) #Load the abundance table x<- read.csv("abundance_table.csv",header=TRUE,row.names=1) x<-t(x) #Perform non-metric distance scaling MDS<-metaMDS(x, distance = "bray", k = 2, trymax = 50) #Normalize the data x<-x/rowSums(x) x<-x[,order(colSums(x),decreasing=TRUE)] #Extract list of top N Taxa N<-21 taxa_list<-colnames(x)[1:N] #Remove "Unknown" and add it to others taxa_list<-taxa_list[!grepl("Unknown",taxa_list)] N<-length(taxa_list) #Generate data for SUMMARIZEplot new_x<-data.frame(x[,colnames(x) %in% taxa_list],Others=rowSums(x[,!colnames(x) %in% taxa_list])) names<-gsub("\\.","_",gsub(" ","_",colnames(new_x))) sink("data.js") cat("var freqData=[\n") for (i in (1:dim(new_x)[1])){ cat(paste("{Samples:\'",rownames(new_x)[i],"\',",sep="")) cat(paste("freq:{",paste(paste(names,":",new_x[i,],sep=""),collapse=","),"},",sep="")) cat(paste("MDS:{",paste(paste(colnames(MDS$points),MDS$points[rownames(new_x)[i],],sep=":"),collapse=","),"}}\n",sep="")) if(i!=dim(new_x)[1]){cat(",")} } cat("];") sink()