2
votes

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)

non-aligned phylogeny

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

2
Is there anyway you can provide some sample data (A sample tree) and perhaps a link to an image of a plot you are trying to replicate?MrFlick
@MrFlick I'll have a look tomorrow to see if i can find an example, but I've edited my question and hopefully my description should be good enough now.Rambatino
That's very helpful. Did you generate the plot in R? If so, can you also share the R code used to make it. It may be possible to make an easy change in the code to do what you want. I do think this sample plot with your description makes sense. Basically you want all the text left-aligned on the right side of the plot with dotted lines connecting the name to the corresponding terminal tree node.MrFlick
@MrFlick I've add the code to make it, though without colours. and yep, that's what I want!Rambatino
@MrFlick Okay, I think it should be really obvious now! ^^Rambatino

2 Answers

3
votes

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

enter image description here

1
votes

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)