tree_layout {phyloseq} | R Documentation

## Returns a data table defining the line segments of a phylogenetic tree.

### Description

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.

### Usage

    tree_layout(phy, ladderize = FALSE)

### Arguments

`phy` | (Required). The `phylo` or `phyloseq-class` object (which must contain a `phylo`genetic tree) that you want to converted to `data.table`s suitable for plotting with `ggplot`2.
`ladderize` | (Optional). Boolean or character string (either `FALSE`, `TRUE`, or `"left"`). Default is `FALSE` (no ladderization). This parameter specifies whether or not to `ladderize` the tree (i.e., reorder nodes according to the depth of their enclosed subtrees) prior to plotting. This tends to make trees more aesthetically pleasing and legible in a graphical display. When `TRUE` or `"right"`, “right” ladderization is used. When set to `FALSE`, no ladderization is applied. When set to `"left"`, the reverse direction (“left” ladderization) is applied.

### Value

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.

### See Also

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.

### Examples

    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")

[Package phyloseq version 1.34.0 Index]