Monday, July 14, 2014

New user controls in phylo.to.map

I just posted a version of the phytools function phylo.to.map, which can be used to project a tree onto a geographic map. Based on some user feedback, including at the Latin American Macroevolutionary Workshop we just held at the Universidad de los Andes in Bogotá, Colombia, I have added a couple of new features & attributes to the function.

First, the function now automatically removes the underscore character ("_") from within species names. Note that this is only for type="phylogram", not type="direct"; although in the latter case it can easily be done manually.

Second, again for type="phylogram", the lines connecting the tree to locations on a geographic map now (by default) arise from the end of the tip label - rather than from the tip itself.

Finally, third, the function now allows user control of the color of both the dashed lines & points connecting species labels to their geographic locations (for type="phylogram"); and of the both the lines and tip dot colors (for type="direct".

These updates are in the latest non-CRAN phytools build. Here's a quick demo:

> packageVersion("phytools") [1] ‘0.4.24’
> ## simulate some realistic looking data
> foo<-function() paste(c(sample(LETTERS,1),
sample(letters,round(runif(n=1,min=3,max=5))),"_",
sample(letters,round(runif(n=1,min=4,max=6)))),
collapse="")
> tree<-pbtree(n=40,tip.label=replicate(40,foo()))
> tree$edge.length<-tree$edge.length*
100/max(nodeHeights(tree))
> lat<-fastBM(tree,sig2=10,bounds=c(-90,90))
> long<-fastBM(tree,sig2=20,bounds=c(-180,180))
> X<-cbind(lat,long)
> ## ok, first the (new) standard plot:
> obj<-phylo.to.map(tree,X,ftype="i",fsize=0.7,
asp=1.2,split=c(0.5,0.5))
objective: 302
...
objective: 220
objective: 218
objective: 218
> ## now let's change the colors:
> plot(obj,colors=c("blue","red"),ftype="i",fsize=0.7,
asp=1.2,split=c(0.5,0.5))
> ## direct projection with different colors
> plot(obj,type="direct",colors=c("red","black"),
fsize=0.7)
That's it.

4 comments:

  1. Dear Liam,

    Is there any way to use this function on a smaller scale, say plotting the phylogeny against a smalle map of a single continent/country?

    Kind regards,

    Wesley

    ReplyDelete
    Replies
    1. Yes. Try the arguments database and regions. - Liam

      Delete
    2. You can also set xlim and ylim based on geographic coordinates.

      Delete
  2. Dear Liam,

    Do you have an example where points can be coloured by a vector of colours? I have tried just inputting that vector and list("black", col_vector) under the argument color, but no luck yet.

    ReplyDelete

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