Sunday, June 9, 2019

Some useful updates & fixes to geo.legend, for overlaying geological time periods on a plotted tree

For a couple of years phytools has had a function called geo.legend which can be used to draw a colorscale legend on top of a plotted tree - by default, using standard geological time scale colors.

Although this function is kind of neat, it had some weird attributes. For instance, it required that the user either plotted the tree backwards in time (then flip the x-axis so the tree would be right-facing), or manually flip the legend color order.

Today I pushed a few fixes that should address this issue, and others such as how the period labels tended to be improperly centered when the number of periods was few. These fixes work with the existing function code so they are a tiny bit hacky, but hopefully users won't run into too many difficulties.

Here's a little demo:

library(phytools)
packageVersion("phytools")
## [1] '0.6.81'
data(anoletree)
anoletree<-as.phylo(anoletree)
anoletree<-geiger::rescale(anoletree,model="depth",
    depth=50)
plotTree(anoletree,ylim=c(-0.16,1)*Ntip(anoletree),
    ftype="i",lwd=1,fsize=0.5)
obj<-geo.legend()

plot of chunk unnamed-chunk-1

obj
## A geological period legend:
##             start    end     color
## Quaternary  2.588  0.000 #FFF27F33
## Neogene    23.030  2.588 #FFE61933
## Paleogene  50.000 23.030 #FD9A5233

That's alright.

Now let's simulate an older tree:

tree<-pbtree(n=200,scale=500)
plotTree(tree,ylim=c(-0.2,1)*Ntip(tree),ftype="off",lwd=1)
geo.legend()

plot of chunk unnamed-chunk-2

Finally, I also added an additional function to the phytools namespace called geo.palette(). It merely returns the geological time scale color palette to the user:

geo.palette()
## A geological period color palette:
##                  start     end     color
## Quaternary       2.588   0.000 #FFF27FFF
## Neogene         23.030   2.588 #FFE619FF
## Paleogene       66.000  23.030 #FD9A52FF
## Cretaceous     145.000  66.000 #7FC64EFF
## Jurassic       201.300 145.000 #34B2C9FF
## Triassic       252.170 201.300 #812B92FF
## Permian        298.900 252.170 #F04028FF
## Carboniferous  358.900 298.900 #67A599FF
## Devonian       419.200 358.900 #CB8C37FF
## Silurian       443.800 419.200 #B3E1B6FF
## Ordovician     485.400 443.800 #009270FF
## Cambrian       541.000 485.400 #7FA056FF
## Precambrian   4600.000 541.000 #F74370FF

That's it.

No comments:

Post a Comment

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