【问题标题】:cca ordiplot length of 'dimnames' [1] not equal to array extent'dimnames' [1] 的 cca ordiplot 长度不等于数组范围
【发布时间】:2020-05-11 05:07:16
【问题描述】:

我正在绘制物种数据(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) 中的错误

这可能与这 3 个不同的物种群有关吗?尽管它们一起构成了 556 个物种?

【问题讨论】:

    标签: r


    【解决方案1】:

    我认为问题在于物种名称需要是列名称(向量名称),而不是行名称。但是你给出的例子不足以让我真正研究它。下次能否请您提供一个可重现的小问题示例。这也使提供帮助和回答您的问题变得更加容易。如果我快速尝试查看问题所在,则在绘制 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 个物种的名称效果不会很好。这可以通过类似 orditorp 函数 (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。我建议先看看你想回答的问题。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2016-06-25
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多