Monday, February 1, 2016

Standardization method for dotTree, and comparison of two different methods for visualizing quantitative character data at the tips of the tree

In the past few days I have posted two different visualization methods that can both be used to visualize continuous trait data for multiple characters across the tips of a tree. The first, phylo.heatmap, plots a multivariate 'heatmap' of trait values for multiple characters in a grid (e.g., 1, 2). The second, dotTree, shows one or multiple traits plotted on the tips of the tree using different sized circles or dots (e.g., 1, 2).

Tonight, I added the same standardization option that was already available in phylo.heatmap to dotTree. This update can be seen here. Having done this, I thought it might be interesting to visually compare the two methods, since they are effectively being used to represent the same data. Here is what that looks like:

library(phytools)
## Loading required package: ape
## Loading required package: maps
## 
##  # ATTENTION: maps v3.0 has an updated 'world' map.        #
##  # Many country borders and names have changed since 1990. #
##  # Type '?world' or 'news(package="maps")'. See README_v3. #
## simulate tree & data for 6 traits
tree<-rtree(n=26,tip.label=LETTERS)
X<-fastBM(tree,nsim=6)
## unstandardized
phylo.heatmap(tree,X)

plot of chunk unnamed-chunk-1

dotTree(tree,X,length=8) ## lengthen the legend

plot of chunk unnamed-chunk-1

## standardized
phylo.heatmap(tree,X,standardize=TRUE)

plot of chunk unnamed-chunk-1

dotTree(tree,X,standardize=TRUE,length=8)

plot of chunk unnamed-chunk-1

That's it.

Update to dotTree visualization method for non-ultrametric trees & multiple traits

I just posted an update to the new function dotTree that I documented in yesterday's post.

This update comes from two places. First, from the fact that for non-ultrametric trees the visualization using the previous version of dotTree looks kind of weird. For instance:

library(phytools)
tree<-rtree(n=26,tip.label=LETTERS)
x<-fastBM(tree)
dotTree(tree,x)

plot of chunk unnamed-chunk-1

It is not terrible, but it would be better if all the plotted tip states lined up at the same place.

Next, when I posted this to Facebook (and, actually in the original email that inspired this method), there was a request to add multiple traits. Putting these betweem the end of the tip and the tip label seemed pretty impractical.

With these factors in consideration, I decided to try a different internal plotting method - the same one that is used in the phytools function plotting method for objects of class "cophylo" (e.g., here).

This is what that looks like for the same data:

dotTree(tree,as.matrix(x),method="phylogram")

plot of chunk unnamed-chunk-2

Using this method internally & moving the dots to the right of the plotted tip labels also makes it very convenient to show multiple traits, which I also added as a feature. For example:

X<-fastBM(tree,nsim=10)
dotTree(tree,X)

plot of chunk unnamed-chunk-3

Once again, this doesn't look very good for trees with more than 60 or 70 taxa:

tree<-rtree(n=60)
X<-fastBM(tree,nsim=12)
dotTree(tree,X,fsize=0.7,cex=0.7)

plot of chunk unnamed-chunk-4

I should warn that there are certainly some bugs still being worked out (some were discovered in the writing of this post), & feedback on bugs, as well as feedback generally, is welcome.

The easiest way to use this function is to update phytools from GitHub using the devtools package, e.g.:

library(devtools)
install_github("liamrevell/phytools")