In the past 24 hrs or so I have done a few things to speed up the new phytools
collapseTree. This function gives an animated, interactive tree
plotter through which users can collapse & expand subtrees of the phylogeny to
& from their ancestral nodes. Code of this new version is
Since the animation requires that the tree be replotted many times in succession,
most of the speed-ups I mentioned involves vectorizing various actions, as well as
avoiding, where ever possible, the need to recalculate quantities. Specifically,
I vectorized the drawing of edges & arcs on the tree (using
draw.arc, respectively), and I allow internally used plotting function,
fan to accepted precalculated values for the
"phylo" object and for the node heights of the tree, since
these must be recomputed every time the same tree is plotted.
I also created a new, internally used function called
nodelabels from the ape package for the simple task of
plotting circles at the nodes & tips of the phylogeny.
Finally, particularly when the tree is very large, I found that the animation
would sometimes “blink” when running. This is because there is a discernible
gap in time between different parts of the tree and node labels being plotted.
To eliminate that phenomenon, I now use the function
hold the elements being sent to the plotting device, and
to flush them.
This actually may turn out to be a handy feature to add to other plotting functions in the phytools package. For instance, compare (on your own machine, of course):
library(phytools) tree<-pbtree(n=100) x<-fastBM(tree) contMap(tree,x,ftype="off") ## appears gradually
##  0
dev.flush() ## appears all at once
##  0
Finally, here is another video showing the use of
##  '0.4.51'
tree<-pbtree(n=150) ## don't run # pruned<-collapseTree(tree)
Cool - no blinking!