I am very exciting that I have received very positive feedback from Ahmed Moustafa and Simon Frost.

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.

library(ggplot2)
library(ggtree)
ggtree(rtree(15)) %<% rtree(30)

It supports different layout.

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

It is chainable.

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

It also supports multiple layers.

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

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

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)

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

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

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

Citation

G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution. doi:10.1111/2041-210X.12628.