Saturday, September 26, 2020

Projecting a continuous trait onto the branches of a tree using variable edge widths

Following on my prior three posts (1, 2, 3), a fourth new addition to the latest CRAN update to phytools is a method for mapping the observed and reconstructed values of a continuous character onto a tree using variable width edges: edge.widthMap.

Here's a quick demo of how it works.

First, let's load some data. This phylogenetic tree and dataset were pulled from Garland et al. (1992).

data(mammal.tree)
data(mammal.data)
lnHomeRange<-setNames(log(mammal.data$homeRange),
    rownames(mammal.data))

For our next step we create our object for plotting using edge.widthMap.

object<-edge.widthMap(mammal.tree,lnHomeRange)
object
## Object of class "edge.widthMap" containing:
## (1) Phylogenetic tree with 49 tips and 48 internal nodes.
## (2) Vector of node values for a mapped quantitative
##     trait.

Finally, let's make our plot.

plot(object,border=1,color=palette()[7],
    legend="log(home range)")

plot of chunk unnamed-chunk-3

Some people seem to like this. I think it looks cool.

3 comments:

  1. Hi Liam,

    I agree, I like this! Is there a way to combine edge.widthMap with a contMap object? I am trying to map two continuous datasets to my tree.

    Thanks! Chelsea

    ReplyDelete
    Replies
    1. You could - but it would be a bit of work.... One trick that jumps to mind is that any "simmap" object can be converted to a standard "phylo" object with singleton nodes using map.to.singleton. Since a "contMap" object encodes the continuous trait along edges using a "simmap" style object, this also applies to the "contMap" tree. Then, you just need to draw the tree with different edge widths (for all the singleton nodes) and different colors. Tell us if you get it to work with this advice, otherwise feel free to email me.

      Delete
  2. This is great Liam! Like Chelsea, I'm wondering if it is possible to color the tree with information of a discrete character, like the function densityMap does. Thanks!

    ReplyDelete

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