用r中的列值标记nmds图

时间:2019-02-22 22:38:11

标签: r plot mds

我运行了metaMDS,并希望通过基于某些数据帧字符的分组来绘制图形和颜色代码。在我的原始数据帧中,df $ yr是年份,而df $ 2是站点。我想按年着色。

caltmds <- metaMDS(df[,3:12], k=3)
plot(caltmds, type = 'n')
cols <- c("red2", "mediumblue")
points(caltmds, col = cols[df$yr])

我也尝试过此post

scl <- 3
colvec <- c("red2", "mediumblue")
plot(caltmds, type = "n", scaling = scl) 
with(df, points(caltmds, display = "sites", col = colvec[yr], pch = 21, bg = colvec[yr]))
text(caltmds, display = "species", cex = 0.8, col = "darkcyan")
with(df, legend("topright", legend = levels(yr), bty = "n", col = colvec, pch = 21, pt.bg = colvec))

一无所获

1 个答案:

答案 0 :(得分:0)

#DATA
df1 = mtcars

mycolors = df1$cyl   #Identify the grouping vector

library(vegan)
m = metaMDS(df1)

x = scores(m)  #Extract co-ordinates

plot(x, col = as.numeric(as.factor(mycolors)))