数据人自己的学习交流平台,以后如果做商业化,收益扣除20%的运营成本,其他都按照积分进行分配。当然最重要的目的还是为了沉淀一些比较好的内容,希望对大家的学习有所帮助。有任何问题和建议可以直接联系QQ 23683716
0 votes
asked in R by (370 points)
edited by

请教下,非计量多元尺度法的结果能显示成类似下图的形式吗?具体特点是样本和变量的点用不同的颜色标注,变量的点有一条从原点出发指向该变量点的单向箭头。谢谢。

1 Answer

+1 vote
answered by (1k points)

之前没有用R做过图, 直接找了MDS的程序分析了下数据,得到的结果直接用plot函数画图,默认出来的是这样的:

经过修饰点,加图示,加文本,加网格,添加箭头后出来的结果如下:

代码如下:

library("vegan")

d <- read.csv("C:/Users/xsmile/Documents/Tencent Files/23683716/FileRecv/Lizard abundance.csv")

str(d)

d2 <- d[,3:10]

d$color <- "Red"

d[which(d$Disturbance=="Disturbed"),]$color<- "Blue"

d$color <- as.factor(d$color )

# Global NMDS using monoMDS

n <- metaMDS(d2)

plot(n)

points(n$points,pch=7,col=as.character(d$color))

#decoration

#ordispider(n,groups = d$Disturbance,label = TRUE)  #add a spider lines for each species to centriod

#ordihull(n,groups = d$Disturbance,lty='dotted')  #add hull convex for each Group.

legend('topright',pch=7,col=levels(d$color),legend =levels(d$Disturbance))

text(n$species,labels = colnames(d2)  ) 

grid(nx=NA,ny=6,lwd=2)

tempforchart <- as.data.frame(n$species)[1:2,]

row.names(tempforchart) <- c(1,2)

tempforchart[1,1] <- 0

tempforchart[1,2] <- 0

for (rowname in rownames(as.data.frame(n$species)))

{

  tempforchart[2,1] <- as.data.frame(n$species)[rowname,1]

  tempforchart[2,2] <- as.data.frame(n$species)[rowname,2]

  #lines(tempforchart,col = "blue",type = "o",lwd = 2,pch=5)

  arrows(tempforchart[1,1],tempforchart[1,2],tempforchart[2,1],tempforchart[2,2],col = "red", lwd = 2, lty = 1)

}

数据如下:
,Disturbance,Species_1,Species_2,Species_3,Species_4,Species_5,Species_6,Species_7,Species_8
Site_1,Disturbed,13,1,3,2,17,5,1,11
Site_2,Disturbed,6,3,1,4,29,5,6,6
Site_3,Disturbed,10,4,2,1,23,1,8,10
Site_4,Disturbed,12,4,4,1,39,4,9,18
Site_5,Disturbed,14,1,4,2,34,0,8,16
Site_6,Undisturbed,6,19,9,0,24,14,18,26
Site_7,Undisturbed,1,7,7,0,2,19,2,10
Site_8,Undisturbed,5,5,9,0,8,7,9,34
Site_9,Undisturbed,14,14,13,0,13,26,6,35
Site_10,Undisturbed,20,6,5,0,16,13,11,27
推荐关注 一起大数据 微博
推荐书籍:
...