首页 > 解决方案 > 如何让 plot.cophylo 忽略缺失值(NA)?

问题描述

我想绘制一个 cophylo 对象,但是其中一个分支有一个缺失值,因此 cophylo 没有正确绘制。

如何更改值或绘制没有分支长度的树?

标签: rphylogeny

解决方案


我无法重现该示例,并且该cophylo()函数似乎可以很好地处理丢失的数据。

    library(phytools)
    #> Loading required package: ape
    #> Loading required package: maps
    set.seed(12345)
    tr1<-pbtree(n=22,tip.label=c(1:22))
    tr2<-pbtree(n=10,tip.label=c(1:10))
    obj<-cophylo(tr1,tr2)
    #> Rotating nodes to optimize matching...
    #> Done.
    plot(obj)

编辑

问题是关于缺少分支长度。首先,这对我来说似乎很可疑,因为缺少分支长度似乎没有意义。但是,现在可以重现该问题。也许您的 NA 实际上是值 0?

    # Now with missing value --> Indeed it doesn't plot
    tr1$edge.length[2] <- NA
    obj<-cophylo(tr1,tr2)
    #> Rotating nodes to optimize matching...
    #> Done.
    plot(obj)

    # Replace NA value with 0? (I am not sure if this makes sense)
    tr1$edge.length[2] <- 0
    obj<-cophylo(tr1,tr2)
    #> Rotating nodes to optimize matching...
    #> Done.
    plot(obj)

编辑 2

问题在于阅读 Newick 文件。特别是,OP 在名称中使用了不允许的字符(例如':')。

reprex 包(v0.3.0)于 2020 年 10 月 26 日创建


推荐阅读