微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在不使用 R 中的 BiodiversityR 包的情况下使用 Bray-Curtis 指数在 PCA 中添加影响因素?

如何解决如何在不使用 R 中的 BiodiversityR 包的情况下使用 Bray-Curtis 指数在 PCA 中添加影响因素?

我正在尝试为我拥有的 PCOA 图添加负载或有影响的物种。我计算了 Bray Curtis 距离矩阵来绘制坐标。现在,我想添加载荷以确定最具影响力的物种。但是,我无法使用 BiodiversityR 软件包,因为 Mac OS 需要安装 tcl-tk。尝试了三天后,我一直无法弄清楚如何。所以我想知道是否有替代的包或方法来确定要添加到图中的加载。如果 BiodiversityR 包有效,我必须为需要完成的工作编写代码评论如何继续。

library(vegan)
set.seed(111)
sp1 <- rnorm(72,mean = 4,1)
sp2 <- rnorm(72,mean = 2,1)
sp3 <- rnorm(72,mean = 3,1)
sp4 <- rnorm(72,mean = 9,1)

sp.abd <- data.frame(sp1,sp2,sp3,sp4)


species.db <- vegdist(sp.abd,method = "bray")
species.db <- vegdist(sp.abd,method = "bray",upper = TRUE,diag = TRUE)
species.db[is.na(sp.abd)] <- 0
species.pcoa <- cmdscale(species.db,eig = TRUE,k = 3)

speciesREL <- sp.abd
for(i in 1:nrow(sp.abd)){
  speciesREL[i,] = sp.abd[i,] / sum(sp.abd[i,])
}

library(BiodiversityR)
species.pcoa <- add.spec.scores(species.pcoa,speciesREL,method = "pcoa.scores")


##PLOT PCOA
explainvar1 <- round(species.pcoa $eig[1] / sum(species.pcoa $eig),3) * 100
explainvar2 <- round(species.pcoa $eig[2] / sum(species.pcoa $eig),3) * 100
explainvar3 <- round(species.pcoa $eig[3] / sum(species.pcoa $eig),3) * 100
sum.eig <- sum(explainvar1,explainvar2,explainvar3)

df1 <- data.frame(species.pcoa$points)

rda.plot <- ggplot(df1,aes(x=X1,y=X2)) + 
  geom_point(aes(size = 3,alpha = 0.5)) +
  geom_hline(yintercept=0,linetype="dotted") +
  geom_vline(xintercept=0,linetype="dotted") +
  coord_fixed()  +
  theme_classic()

rda.plot

##Adding lines
#df2 <- data.frame(species.pcoa$cproj)

# rda.biplot <- rda.plot +
#   geom_segment(data=df2,aes(x=0,xend=X1,y=0,yend=X2),#                color="black",arrow=arrow(length=unit(0.01,"npc"))) +
#   geom_text(data=df2,#             aes(x=X1,y=X2,label=rownames(df2),#                 hjust=0.5*(1-sign(X1)),vjust=0.5*(1-sign(X2))),#             color="black",size=4) + 
# rda.biplot 

例如,在没有任何转换的情况下添加“最具影响力”的物种看起来像这样:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。