CCA Ordiplot 长度为 'dimnames' [1] 不等于阵列范围



我正在绘制一个物种数据(556个物种(和环境参数(eiv(的cca,但在图中添加物种名称作为标签时遇到了问题。物种名称位于等级库数据帧的标题行中。

物种数据有369种草本植物、135种苔藓和52种地衣,我试图在图中对它们进行不同的标记:

cca1<- vegan::cca(log1p(spec), log1p(eiv))
col<-c(rep("grey", 369), rep("red", 135),rep("green",52))
shp<- c(rep(1, 369), rep(15, 135),rep(17,52))
cex<- c(rep(0.5, 369), rep(0.7, 135),rep(0.7,52))
lgd<- c(rep("Herbs", 369), rep("Mosses",135), rep("Lichen",52))
spnames<-colnames(spec[,1:556])
ordiplot (cca1, display = 'sp', type = 'n', main ="CCA Alpine Species using EIV" )
points(cca1, display = "species", cex = cex, pch = shp,  col = col, scaling=3)
text(cca1, display = "species",labels=spnames,scaling=3)
text(cca1, display = "bp", col = "grey40", cex = 0.8, scaling=3)
legend(x="topright", legend=unique(lgd), col = unique(col), pch = unique(shp))

当我运行'text(cca1,display="species",labels=spnames,scaling=3(命令时,我得到了这个错误:

dimnames(x(中出错<-dn:"dimnames"[1]的长度不等于数组范围

这可能与这三个不同的物种群有关吗?尽管它们共有556个物种?

我认为问题是物种名称需要是列名(向量名称(,而不是行的名称。但你给出的例子不足以让我真正研究它。下次你能提供一个可重复的小例子吗。这也使得提供帮助和回答问题变得更加容易。如果我很快想知道问题是什么,当我绘制CCA的结果时,我不会遇到问题,请参阅下面的示例。

spec <- as.data.frame(matrix(ncol = 1, nrow = 100))
for(i in 1:556){
spec[,paste("sp",i)] <- rbinom(100,1,0.5)
}
#This is awkward, ignore this bad coding part
spec <- spec[-1]
eiv <- as.data.frame(matrix(ncol = 1, nrow = 100))
for(i in 1:10){
eiv[,paste("var", i)] <- rnorm(100)
}
#again very akward
eiv <- eiv[-1]
cca1 <- vegan::cca(spec, eiv)
col<-c(rep("grey", 369), rep("red", 135),rep("green",52))
shp<- c(rep(1, 369), rep(15, 135),rep(17,52))
cex<- c(rep(0.5, 369), rep(0.7, 135),rep(0.7,52))
lgd<- c(rep("Herbs", 369), rep("Mosses",135), rep("Lichen",52))
spnames<-colnames(spec[,1:556])
ordiplot (cca1, display = 'sp', type = 'n', main ="CCA Alpine Species using EIV" )
points(cca1, display = "species", cex = cex, pch = shp,  col = col, scaling=3)
text(cca1, display = "species",labels=spnames,scaling=3)
text(cca1, display = "bp", col = "grey40", cex = 0.8, scaling=3)
legend(x="topright", legend=unique(lgd), col = unique(col), pch = unique(shp))

此外,在一个图中显示556个物种的名称也不会像你在结果中看到的那样效果很好。这可以用orditop函数来减少(https://fromthebottomoftheheap.net/2013/01/13/decluttering-ordination-plots-in-vegan-part-2-orditorp/),但我不太熟悉。或者,删除一些不经常出现的物种。我想这是必要的,因为它们无论如何都会影响你的CCA的"解释变化"。你也可以通过查看物种得分来解决CCA的数字结果。

sum.cca <- summary(cca1)
sum.cca$species

基于此,你可以选择一些相对于最具解释性的CCA轴具有非常独特位置的物种,并对此进行讨论。此外,对这些物种重新执行CCA可以给出更好的情节,但当然是非常有偏见的,因为你删除了大部分物种,并在极端情况下产生了新的CCA。我建议你先看看你想回答的问题。

希望这能帮助

相关内容

最新更新