我正在尝试创建一个系统发展史,其中我编码的分支长度是用颜色而不是长度表示的。所以我希望分支长度相等。
下面是我的代码:
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()时,树仍然显示分支长度。有人知道怎么解决这个问题吗?
发布于 2018-06-25 13:28:13
不幸的是,在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的更多信息。
https://stackoverflow.com/questions/50988405
复制相似问题