Tuesday, November 8, 2016

New methods & flexibility for phylogenetic scattergram plotting

One of my favorite visualization methods for continuous character data is a plotting method that I like to call the phylogenetic scattergram. I originally described this method in a 2014 book chapter, but the basic idea is that the diagonal of the scattergram matrix are contMap style plots, whereas the off-diagonals show bivariate phylomorphospace plots.

Unfortunately, the method hasn't seen a lot of use - in fact, in spite of over 900 citations of phytools to date, many of which have employed phytools plotting methods, I have not yet seen this method used in publication. (Readers, please correct me if I'm wrong.) There could be a couple of reasons for this. One is that the method is hidden within the multifunctional fancyTree. A second, is that it is pretty much a 'canned' routine with very little user flexibility.

I just pushed some updates to this plotting method in particular. I may add some later, but the key change is that now the function returns a special object class to the user which contains the vertices of the phylomorphospaces & the contMap objects, allow the user to re-plot this graphic using a generic plotting method.

Here's a quick & dirty demo:

library(phytools)
packageVersion("phytools")
## [1] '0.5.58'
tree
## 
## Phylogenetic tree with 26 tips and 25 internal nodes.
## 
## Tip labels:
##  C, V, W, Y, Z, F, ...
## 
## Rooted; includes branch lengths.
X
##         [,1]        [,2]        [,3]
## C  0.9665115  0.77530224  0.40632876
## V  1.6173641 -0.45503363 -0.73182369
## W -0.6728310 -1.78553717 -0.73184711
## Y  0.6401576 -0.98353854 -0.75233676
## Z -0.3113427 -1.98426527  0.33925707
## F  0.1187115 -2.61233154 -0.08975610
## D  1.5895157 -0.71237881  0.92154701
## R -0.5030924 -1.51789676 -0.78617234
## K  0.5098685  0.31009204 -1.18026220
## A  0.1920934  0.71295014  0.11839322
## E  1.0830233 -0.50666857  1.41188048
## L  0.8582965 -2.59273478  1.08312946
## P  1.8567962 -0.80005701  0.50214655
## S  0.8637203 -0.45019212 -1.27152932
## J -0.9233336 -1.38611041 -0.71207670
## Q -0.3853552 -2.08781313  0.04041544
## B -0.4932460  0.61998051  1.53674614
## M  0.8331827  2.37457042  1.01991590
## T -0.4105719  0.46076752  2.83153423
## X  0.1547002  2.70289054  0.40174635
## G  0.2030019  1.58626182 -0.82439232
## O  2.1950008  0.46824451 -0.36459761
## U  0.6118033  0.79979993 -0.39982433
## I  2.8565573  0.14631413 -1.16155019
## H  2.9150287  0.73173923 -1.39485319
## N -0.7391192  0.08329559  0.08744501
obj<-fancyTree(tree,X=X,type="scattergram")
## Computing multidimensional phylogenetic scatterplot matrix...

plot of chunk unnamed-chunk-1

obj
## 
## Object of class "phyloScattergram" for 3 continuous traits.
## let's flip the colors of the "contMap" objects
obj$contMaps<-lapply(obj$contMaps,setMap,invert=TRUE)
plot(obj)

plot of chunk unnamed-chunk-1

## change blue-red
obj$contMaps<-lapply(obj$contMaps,setMap,c("blue","purple","red"))
plot(obj)

plot of chunk unnamed-chunk-1

## change to grey scale
obj$contMaps<-lapply(obj$contMaps,setMap,c("white","black"))
plot(obj)

plot of chunk unnamed-chunk-1

That's more or less all I've added so far, but further flexibility is certainly possible.

1 comment:

  1. It is possible to change the tip labels colors? I want to assign colors to them and then add a legend in a side, so you can see the "green point" and understand where is the "specie X" in the scatterplot.

    ReplyDelete

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.