-
Notifications
You must be signed in to change notification settings - Fork 178
reproduce ggphylo example using ggtree
Guangchuang Yu edited this page Aug 31, 2015
·
7 revisions
ggphylo
supports plotting a list of phylo
objects.
require(ape)
require(ggphylo)
tree.list = rmtree(3, 20)
ggphylo(tree.list)

AND plotting data along tree
```r
n <- 40; x <- rtree(n); n.nodes <- length(nodes(x))
bootstraps <- 100 - rexp(n.nodes, rate=5) * 100
pop.sizes <- pmax(0, rnorm(n.nodes, mean=50000, sd=50000))
for (i in nodes(x)) {
x <- tree.set.tag(x, i, 'bootstrap', bootstraps[i])
x <- tree.set.tag(x, i, 'pop.size', pop.sizes[i]) }
plot.args <- list(
x,
line.color.by='bootstrap',
line.color.scale=scale_colour_gradient(limits=c(50, 100), low='red', high='black'),
node.size.by='pop.size',
node.size.scale = scale_size_continuous(limits=c(0, 100000),
range=c(1, 5)), label.size=2
)
do.call(ggphylo, plot.args)
In ggtree
, multiPhylo
object is supported.
require(ggplot2)
require(ggtree)
ggtree(tree.list, ladderize=F, aes(color=.id)) + facet_wrap(~.id) +
geom_point() + geom_text(subset=.(!isTip), aes(label=node), hjust=-.2, size=3) +
geom_tiplab(size=4, hjust=-.2)
ggtree
defined fortify
method to convert tree object to data.frame
, user can operate this data.frame
to add more information, and use ggplot
with geom_tree
that defined in ggtree
to add tree layer.
df <- fortify(x, ladderize=F)
df$bootstrap <- bootstraps
df$pop.size <- pop.sizes
ggplot(df, aes(x, y, color=bootstrap)) + geom_tree() + geom_point(aes(size=pop.size)) +
scale_color_gradient(limits=c(50, 100), low="red", high="black") +
geom_tiplab(size=3, color="black", hjust=-.5)