Link tip labels to phylogenetic tree using dots

▼魔方 西西 提交于 2020-01-13 05:50:13

问题


I'm trying to produce a non-ultrametric tree using the ape package in R and the function plot.phylo(). I'm struggling to find any documentation on how to keep the tip label vertically aligned on their left edge and with a series of dots (variable length) linking the species' name to the tip of the node.

Any help would be much appreciated as well as links to other packages within R that may be able to achieve this.

An example of the newick tree

I don't have any tree examples of what i want, however, the description seems self explanatory. the labels would all be shifted to the very right, and aligned on their left side, then a series of dots (.......) would link the label to where there old position was.

  MLJTT = newickTree (as a string)
  plot.phylo(read.tree(text = MLJTT), show.tip.label = T,use.edge.length = T, no.margin = T, cex = 0.55)

And example of three that I want to copy the layout of from here:


回答1:


Ok, I ended up slightly modifying the default plot.phylo code to accomidate such a change. Here's how it looks

library(ape)
plot.phylo2 <- plot.phylo
environment(plot.phylo2) <- environment(plot.phylo)

body(plot.phylo2)[[c(34, 3, 6, 3, 4, 3)]] <- quote({
    mx <- max(xx[1:Ntip])
    segments(xx[1:Ntip], yy[1:Ntip] + loy, mx, yy[1:Ntip] + loy, 
        lty=2, col="grey")
    text(mx + lox, yy[1:Ntip] + loy, x$tip.label, adj = adj, 
        font = font, srt = srt, cex = cex, col = tip.color)
})

This is somewhat fragile and may change in different version of ape, I've tested this with version ape_3.1-4. You can check if this will work by verifying that

body(plot.phylo)[[c(34, 3, 6, 3, 4, 3)]]

returns

text(xx[1:Ntip] + lox, yy[1:Ntip] + loy, x$tip.label, adj = adj, 
    font = font, srt = srt, cex = cex, col = tip.color)

just to make sure we are changing the correct line. But the code above basically replaces that line where the labels are drawn by moving the x axis where they are drawn and adding in the segments for the dotted lines. Then you can run this with your test data

MLJTT = read.tree(text="..<sample data>..")
plot.phylo2(MLJTT, 
    show.tip.label = T,use.edge.length = T, no.margin = T, cex = 0.55)

And this produces




回答2:


I think what you may be looking for is the argument to plot.phylo:

align.tip.label = TRUE

Have you tried this?

MLJTT <- rtree(100)
plot.phylo(MLJTT, show.tip.label = T, align.tip.label = T, use.edge.length = T, no.margin = T, cex = 0.55)


来源:https://stackoverflow.com/questions/25276322/link-tip-labels-to-phylogenetic-tree-using-dots

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!