I naively assumed that this would always be true for trees in "cladewise" order, but in fact this is not the case. Let's read the same tree from "Nexus" format, which in this case might look something like this:

The issue with plotting arises because I assumed that the tip numbers were numerically ordered according the left-to-right order of the Newick string and simply evenly spaced the tips on the basis of this numerical order (which results in branch crossing when the tips are not ordered this way, as evidenced by the figure above). Luckily, this was not difficult to solve. I merely changed the line of code in which I assigned vertical coordinates to all the tips from:

Y[1:n]

to:

Y[cw$edge[cw$edge[,2]<=length(cw$tip),2]]

which seems to do the trick, as if we replot the tree above, our branch crossing is solved:

I have posted the fixed version on my R phylogenetics page (direct link to code here) and I will incorporate this into the next alpha release of "phytools."

1 comment:

By chance Joe Felsenstein noted yesterday on his PHYLIP facebook page that this year marks the 25th anniversary of the Newick tree file format:

"Two weeks ago (26 June) was the 25th anniversary of the Newick tree file format. It was invented by Chris Meacham for a tree plotting program that was the ancestor of Drawtree. It was formalized by a committee called by me, which met on 25 and 26 June, 1986 and had the second meeting at Newick's seafood restaurant in Dover, New Hampshire. . . ."

About this blog

This web-log chronicles the development of new tools for phylogenetic analyses in the phytools R package. Unless you a reading a very recent page of the blog, I recommend that you install the latest CRAN version of phytools (or latest beta release) before attempting to replicate any of the analyses of this site. That is because the linked functions may be archived, and very likely have been replaced by newer versions.