Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

Code no longer working for changing the shapes/colors of points in a metaMDS in vegan in R

I am sure there is an easy answer for this. I have been using this code for years and the other day at work I went to make an ordination, and it stopped working. :( Granted, it has been at least a year since I ran this particular code so maybe the package has changed with an update. Also, there is probably a better way to do this, but this is code I got from someone and it has always worked.

I will give the example with an older data set of mine, since I am running into the same issue with this old data set as the one I have at work. Pretty basic, ecological data with otu frequencies and site characteristics (this is a small look, there are three treatments and three species, 46 otus). This is similar to the dune or other included data sets in R:

treatment by species table

For the ordination, I want the shapes to be the different plant species and the colors to be the different treatments. Here is the code I have always used in the past and had it work ever time:

data1<-read.csv("treatment_by_species.csv")
#data frame with fungal otus
fungal_measure<-data.frame(data1[,3:48],row.names=NULL)

#Lables for graph
trtlabels<-data1[,c(1,1)]

splabels<-data1[,c(1,2)]

#distance matrix
dm=bcdist(fungal_measure)
meta_out=metaMDS(dm,k=2,trymax=9999,utotransform=F)
meta_out
windows(title="meta_out")
stressplot(meta_out)

#graph
color1=c("black","grey","grey96")
windows()
plot(meta_out$points,type="n",xlim=c(-0.6,0.6),ylim=c(-0.6,0.6))
points(meta_out$points,cex=1.5,pch=c(21,22,24)[splabels$Species],
       bg=color1[trtlabels$Treatment])
legend("topleft",bty="n",pch=c(21,22,24,15,15,15),
       col=c("black","black","black","black","grey","grey96"),
       legend=c("Aspen","Pine","Spruce","FFM","Peat","Subsoil"))

So what happens is the blank graph will come up just fine, but the points won't graph at all and there is no error message. I am guessing it has something to do with how I am coding the labels. If someone could point to a post or easier way to do this, it would be most appreciated. Always a bummer when things stop working.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...