Skip to content

reproduce figtree example using ggtree

Guangchuang Yu edited this page Jul 24, 2019 · 5 revisions

Figtree example

FigTree is designed for viewing beast output as demonstrated by their example data:

reproduce using ggtree

BEAST output is well supported by ggtree and it's easy to reproduce such a tree view. ggtree supports parsing beast output by read.beast function. We can visualize the tree directly by using ggtree function. Since this is a time scale tree, we can set the parameter mrsd to most recent sampling date.

require(ggplot2)
require(ggtree)
x <- read.beast("/Applications/FigTree/influenza.tree")
ggtree(x, right=TRUE, mrsd="2014-04-02", aes(color=height)) + theme_tree2() +
	geom_text(aes(x=max(x), label=label), size=1, hjust=-.3) +
		scale_x_continuous(breaks=c(1992, 1995, 1997, 2000, 2002, 2005), minor_breaks=seq(1992, 2005, 1)) +
			geom_segment(aes(xend=max(x)+.20, yend=y), linetype="dotted", size=.1) +
				theme(panel.grid.major   = element_line(color="black", size=.2),
					  panel.grid.minor   = element_line(color="grey", size=.2),
					  panel.grid.major.y = element_blank(),
					  panel.grid.minor.y = element_blank())