【问题标题】:'use.edge.length = FALSE' doesn't seem to work when using plotBranchbyTrait() in phytools在 phytools 中使用 plotBranchbyTrait() 时,'use.edge.length = FALSE' 似乎不起作用
【发布时间】:2018-06-22 12:54:11
【问题描述】:

我正在尝试创建一个系统发育,其中我编码的分支长度用颜色而不是长度表示。所以我希望分支长度相等。

这是我的代码:

plotBranchbyTrait(tree.scaled, tree.scaled$edge.length, mode=c("edges"),palette="rainbow", use.edge.length = FALSE, node.depth = 2)

我的理解是use.edge.length = FALSE 应该使分支长度相等,如果我使用plot.phylo() 对树进行编码,它就会这样做。但是当我使用plotBranchbyTrait() 时,树仍然会显示分支长度。有谁知道如何解决这个问题?

【问题讨论】:

    标签: r tree branch phylogeny


    【解决方案1】:

    不幸的是,可选参数(...) 没有直接传递给plotBranchbyTrait 函数中的plot.phylo。一种不优雅的解决方法是直接在 R 中修改正文以添加硬编码的use.edge.length = FALSE 选项。

    您可以通过创建一个新函数并使用body(foo)[[line_of_interest]] <- substitute(my_new_line <- that_does_something) 对其进行修改来做到这一点。以下示例应该可以工作:

    ## Back up the function
    plotBranchbyTrait_no_edge_length <- phytools::plotBranchbyTrait
    
    ## The line to modify:
    body(plotBranchbyTrait_no_edge_length)[[34]]
    # xx <- plot.phylo(tree, type = type, show.tip.label = show.tip.label, 
    #    show.node.label = show.node.label, edge.color = colors, edge.width = edge.width, 
    #    edge.lty = edge.lty, font = font, cex = cex, adj = adj, srt = srt, 
    #    no.margin = no.margin, root.edge = root.edge, label.offset = label.offset, 
    #    underscore = underscore, x.lim = x.lim, y.lim = y.lim, direction = direction, 
    #    lab4ut = lab4ut, tip.color = tip.color, plot = plot, rotate.tree = rotate.tree, 
    #    open.angle = open.angle, lend = 2, new = FALSE)
    
    
    ## Modify the line 34 by adding `use.edge.length = FALSE`
    body(plotBranchbyTrait_no_edge_length)[[34]] <- substitute( xx <- plot.phylo(use.edge.length = FALSE, tree, type = type, show.tip.label = show.tip.label, show.node.label = show.node.label, edge.color = colors, edge.width = edge.width,  edge.lty = edge.lty, font = font, cex = cex, adj = adj, srt = srt, no.margin = no.margin, root.edge = root.edge, label.offset = label.offset, underscore = underscore, x.lim = x.lim, y.lim = y.lim, direction = direction, lab4ut = lab4ut, tip.color = tip.color, plot = plot, rotate.tree = rotate.tree, open.angle = open.angle, lend = 2, new = FALSE) )
    
    ## Testing whether it worked
    library(phytools)
    tree <- pbtree(n=50)
    x <- fastBM(tree)
    ## With use.edge.length = TRUE (default)
    plotBranchbyTrait(tree, x, mode = "tips", edge.width = 4, prompt = FALSE)
    
    ## With use.edge.length = FALSE
    plotBranchbyTrait_no_edge_length(tree, x, mode = "tips", edge.width = 4, prompt = FALSE)
    

    您可以找到更多关于如何修改函数here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      相关资源
      最近更新 更多