visualizing node labels of MAP tree in R

217 views
Skip to first unread message

Jasmine Mah

unread,
Nov 19, 2020, 1:47:08 PM11/19/20
to revbayes-users
Hi,

This is perhaps the wrong group to post in, but I am a little frustrated and wondering whether this issue with the tree output file is specific to RevBayes.

I would like to plot the maximum a posteriori tree in R and show the posterior probabilities as node labels. I've used ape::read.nexus() to import the nexus tree file; however, while tip labels and branch lengths import, node labels do not. For instance, this is what comes up when I inspect the phylo object:

Phylogenetic tree with 46 tips and 45 internal nodes.

Tip labels:
  Tadh_1, Tadh_20, Tadh_25, Tadh_26, Tadh_27, Tadh_18, ...

Rooted; includes branch lengths.

As a result, I cannot plot node labels in downstream applications, such as ggtree. Oddly enough, I can visualize the node labels in Figtree, but I would like to annotate the tree in R and cannot export it from Figtree in a format that preserves the node labels (the node labels do not survive conversion to Newick).

What program is everyone using to visualize and annotate trees in R? Has anyone else run into this or is this a problem that is specific to my workflow?

Cheers,
Jasmine

andyf...@gmail.com

unread,
Nov 19, 2020, 2:41:23 PM11/19/20
to revbayes-users
Hi Jasmine,

When I need to read or write trees with node annotations, I use phylotate. It does take a little data wrangling, because it stores all the annotations as a string when reading in, so you'll need to extract what you want and put it where it needs to be for downstream work. But all the information will read in.

Best,
Andy

maya.le...@gmail.com

unread,
Nov 19, 2020, 9:06:15 PM11/19/20
to revbayes-users
Hi Jasmine, 

I use ggtree and use `treeio::read.beast()` to import the MCC tree as a treedata S4 object, then you will find node info such as posteriors in tree@data. 
Then you could plot the posteriors as labels, for example:

```
tree <- treeio::read.beast(mcc_file)

ggtree::ggtree(tree) + geom_text2(aes(label=round(as.numeric(posterior), 2), 
               x=branch), vjust=0) 
```

Hope this helps!
- Maya

On Thursday, November 19, 2020 at 10:47:08 AM UTC-8 jasmi...@yale.edu wrote:
Reply all
Reply to author
Forward
0 new messages