Returns a data table defining the line segments of a phylogenetic tree.
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.
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.
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")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.