Description Usage Arguments Value See Also Examples
This function takes a phylo
or phyloseq-class
object
and returns a list of two data.table
s suitable for plotting
a phylogenetic tree with ggplot
2.
1 | tree_layout(phy, ladderize = FALSE)
|
phy |
(Required). The |
ladderize |
(Optional). Boolean or character string (either
|
A list of two data.table
s, containing respectively
a data.table
of edge segment coordinates, named edgeDT
,
and a data.table
of vertical connecting segments, named vertDT
.
See example
below for a simple demonstration.
An early example of this functionality was borrowed directly, with permission,
from the package called ggphylo
,
released on GitHub at:
https://github.com/gjuggler/ggphylo
by its author Gregory Jordan gjuggler@gmail.com.
That original phyloseq internal function, tree.layout
, has been
completely replaced by this smaller and much faster user-accessible
function that utilizes performance enhancements from standard
data.table
magic as well as ape-package
internal C code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | library("ggplot2")
data("esophagus")
phy = phy_tree(esophagus)
phy <- ape::root(phy, "65_2_5", resolve.root=TRUE)
treeSegs0 = tree_layout(phy)
treeSegs1 = tree_layout(esophagus)
edgeMap = aes(x=xleft, xend=xright, y=y, yend=y)
vertMap = aes(x=x, xend=x, y=vmin, yend=vmax)
p0 = ggplot(treeSegs0$edgeDT, edgeMap) + geom_segment() + geom_segment(vertMap, data=treeSegs0$vertDT)
p1 = ggplot(treeSegs1$edgeDT, edgeMap) + geom_segment() + geom_segment(vertMap, data=treeSegs1$vertDT)
print(p0)
print(p1)
plot_tree(esophagus, "treeonly")
plot_tree(esophagus, "treeonly", ladderize="left")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.