[ggtree] updating a tree view using %<% operator

February 9, 2015
By

[This article was first published on YGC » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I am very exciting that I have received very positive feedback from Ahmed Moustafa and Simon Frost.
Screenshot 2015-02-10 10.27.27
Screenshot 2015-02-10 10.27.07

ggtree now has equipped with a lot of new features. This time, I would like to introduce the replace operator, %<%.

Suppose we have build a tree view using ggtree with multiple layers, we don’t need to run the code again to build a new tree view with another tree. In ggtree, we provides an operator, %<%, for updating tree view.

?View Code RSPLUS

1
2
3
library(ggplot2)
library(ggtree)
ggtree(rtree(15)) %<% rtree(30)

Screenshot 2015-02-10 10.22.07

It supports different layout.

?View Code RSPLUS

1
ggtree(rtree(15), layout="unrooted", ladderize=FALSE) %<% rtree(45)

Screenshot 2015-02-10 10.23.48

It is chainable.

?View Code RSPLUS

1
2
3
ggtree(rtree(15), layout="cladogram", ladderize=FALSE) %<% 
    rtree(30) %<% 
       rtree(45)

Screenshot 2015-02-10 10.23.14

It also supports multiple layers.

?View Code RSPLUS

1
2
3
(ggtree(rtree(15), layout="fan") + 
    geom_point(aes(shape=isTip, color=isTip))) %<% 
      rtree(40)

Screenshot 2015-02-10 10.25.31

In the final example, we parse rst file from BaseML output and annotate the tree with marginal_AA_subs.

?View Code RSPLUS

1
2
3
4
5
6
rstfile <- system.file("extdata/PAML_Baseml", "rst", package="ggtree")
tipfas <- system.file("extdata", "pa.fas", package="ggtree")
rst <- read.paml_rst(rstfile, tipfas)
 
p <- plot(rst, annotation="marginal_AA_subs", annotation.color="steelblue")
print(p)

Screenshot 2015-02-10 10.51.17

We have ancestral sequences inferred from CodeML with the same tree. We can use this new data to update the tree view.

?View Code RSPLUS

1
2
3
rstfile <- system.file("extdata/PAML_Codeml", "rst", package="ggtree")
rst <- read.paml_rst(rstfile, tipfas)
p %<% rst

Screenshot 2015-02-10 10.53.41

In these two figures, we can found that they have different evolution distances, and substitutions inferred from BASEML and CODEML are slightly different.

PS: wanna to generate a lovely heart using ggplot2, click here and here.

Related Posts

To leave a comment for the author, please follow the link and comment on their blog: YGC » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)