Internal node number
Some of the functions in ggtree
work with clade and accept a parameter of internal node number. To get the internal node number, user can use geom_text2
to display it:
nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
ggtree(tree) + geom_text2(aes(subset=!isTip, label=node), hjust=-.3) + geom_tiplab()
Another way to get the internal node number is using MRCA()
function by providing a vector of taxa names. The function will return node number of input taxa’s most recent commond ancestor (MRCA). It works with tree and graphic object.
## [1] 17
## [1] 21
## [1] 17
view Clade
ggtree
provides a function viewClade
to visualize a clade of a phylogenetic tree.
group Clades
The ggtree
package defined several functions to manipulate tree view. groupClade
and groupOTU
methods were designed for clustering clades or related OTUs. groupClade
accepts an internal node or a vector of internal nodes to cluster clade/clades.
Both groupClade
and groupOTU
work fine with tree and graphic object.
The following command will produce the same figure.
With groupClade
and groupOTU
, it’s easy to highlight selected taxa and easy to select taxa to display related features.
group OTUs
groupOTU
accepts a vector of OTUs (taxa name) or a list of OTUs. groupOTU
will trace back from OTUs to their most recent common ancestor and cluster them together. Related OTUs are not necessarily within a clade, they can be monophyletic (clade), polyphyletic or paraphyletic.
groupOTU
can also input a list of tip groups.
cls <- list(c1=c("A", "B", "C", "D", "E"),
c2=c("F", "G", "H"),
c3=c("L", "K", "I", "J"),
c4="M")
tree <- groupOTU(tree, cls)
library("colorspace")
ggtree(tree, aes(color=group, linetype=group)) + geom_tiplab() +
scale_color_manual(values=c("black", rainbow_hcl(4))) + theme(legend.position="right")
groupOTU
also work with graphic object.
p <- ggtree(tree)
groupOTU(p, LETTERS[1:5]) + aes(color=group) + geom_tiplab() + scale_color_manual(values=c("black", "firebrick"))
The following example use groupOTU
to display taxa classification.
collapse clade
With collapse
function, user can collapse a selected clade.
expand collapsed clade
The collapsed clade can be expanded via expand
function.
scale clade
Collpase selected clades can save some space, another approach is to zoom out clade to a small scale.
multiplot(ggtree(tree) + geom_hilight(21, "steelblue"),
ggtree(tree) %>% scaleClade(21, scale=0.3) + geom_hilight(21, "steelblue"),
ncol=2)
Of course, scaleClade
can accept scale
larger than 1 and zoom in the selected portion.
rotate clade
A selected clade can be rotated by 180 degree using rotate
function.
flip clade
The positions of two selected clades (should share a same parent) can be flip over using flip
function.
open tree
ggtree
supports fan
layout and can also transform the circular
layout tree to a fan
tree by specifying an open angle
to open_tree
function.
rotate tree
Rotating a circular
tree is supported by rotate_tree
function.
Interactive tree manipulation
Interactive tree manipulation is also possible, please refer to https://guangchuangyu.github.io/2016/06/identify-method-for-ggtree.