Learn R Programming

Powerful phylogenetic tree and alignment plots with ggphylo

ggphylo provides convenient functions and tools for visualizing phylogenetic data in R. A variety of methods are provided to simplify the process of working with phylo objects (e.g., phylogenies derived from the ape package), and the ggphylo function allows one to easily visualize data along phylogenetic trees.

Examples

More Info

See the vignette for examples of the package's main functionality.

Copy Link

Version

Version

0.1

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Gregory Jordan

Last Published

February 15th, 2017

Functions in ggphylo (0.1)

checkLabel

Checks a tree for a valid label, optionally removing bad characters on the way. This is currently a no-op, to avoid interfering with the NHX annotation support.
is.tree

Returns TRUE if the given object appears to be a valid tree object for the purposes of this package.
label.phylo

Returns the label for the given node. Alias for tree.label.for.node. Given a nice short nickname due to its usefulness.
GeomJoinedSegment

Create a geom_joinedsegment which joins together segments with 'round' corners. Looks MUCH nicer. See https://groups.google.com/forum/?fromgroups#!topic/ggplot2/movv0f_MSuY
geom_joinedsegment

Create the function for geom_joinedsegment
as.character.phylo

Turns a phylo object into a Newick format string representation, including NHX annotations if the tree contains any tags.
is.leaf.phylo

as.data.frame.phylo

Turns a phylo object into a data frame
clado.build

ggphylo

sort.df.by.tree

labels.phylo

Returns labels corresponding to all or some subset of the nodes in a tree.
tags.into.df

Given a phylo object and a data frame, transform all the tags from the tree ' into columns of the data frame. Rows of the data frame are linked to the tree via a required 'node' column, which must contain integer indices of the associated node.
nodes

Returns a vector of node indices for all nodes (leaves plus internal nodes) in the tree.
leaves

Returns a vector of node indices for all the leaves in the tree.
theme_phylo_black

A white-on-black theme for futuristic plots.
order.nodes.visually

Returns the indices of all nodes in the tree, arranged in the order in which they would be displayed in a 2-dimensional phylogram plot. In other words, the parent node of two leaf nodes will be placed directly in between its two children, since the parent node is usually placed at the midpoint between two leaf nodes in a plot.
theme_phylo_blank

A mostly-blank theme for simple plots. Ruthlessly taken from ggdendro, courtesy of Andrie de Vries http://cran.r-project.org/web/packages/ggdendro/index.html
tags.phylo

tags.to.nhx.string

Converts a list of tags to an NHX annotation string.
tree.branch.length

Extracts the length of the branch above the given node. Returns 0 if the node is root.
tree.foreach

Loops over nodes in the tree, applying a function using each node as an argument. Optionally, either the leaves or internal nodes can be dropped from the iteration.
tree.get.label

tree.child.nodes

Return a list (not a vector!) of the node indices of the given node's direct children. Returns (-1, -1) if the given node is a leaf.
tree.extract.clade

Returns the sub-tree beneath the given node.
tree.depth.to.root

Returns the length from the tree root to the given node. Note: the node can be given either as a node index or a tip label.
tree.apply.branchlengths

Removes branch lengths from a tree
tree.extract.subtree

Returns the minimum sub-tree connecting the given leaf nodes
tree.layout

Returns a data frame defining segments to draw the phylogenetic tree.
tree.find

tree.read

Reads a tree and returns a phylo object. Note: this function was taken largely from the ape code base, but some alterations were made in order to support NHX formatted trees and to fix some bugs. Only files and strings with a single tree are allowed.
tree.label.for.node

Returns the label for a given node in the tree.
tree.leaves.beneath

Returns the number of leaves beneath a node in the tree (where a leaf node is defined as having 1 leaf beneath)
tree.normalize.branchlengths

Normalizes the branch lengths of a tree for cleaner 2-dimensional plotting.
tree.set.tag

Sets the tag for a given node to the specified value. Returns the same tree structure with the new tag in place.
tree.read.nhx

Reads a tree annotated with NHX-formatted annotations. A phylo object is returned, with annotations stored as tag-value lists. Several convenience functions are provided for accessing these annotations; see 'See Also' below.
tree.set.label

Replaces the label of a given node and returns a new phylo object
tree.is.leaf

Determine if the given node is a leaf or an internal node.
tree.parent.node

Extracts the parent node index for the given node. Returns -1 if the node is root. Return the index of the node directly above the given node. Returns -1 if the given node is root.
tree.to.string

tree.has.tags

Determines whether the given phylo object contains tags or not.
tree.total.branch.length

Returns the total branch length of the tree
tree.get.tags

Retrieves a list of all tags for the given node.
tree.get.root

Returns the index of the root node in the tree, or NA if there is no root
tree.as.data.frame

Create a data frame from a phylo object where each row corresponds to a node in the tree.
tree.scale.by

Scales the tree by a given multiplicative factor.
tree.scale.to

Scales the tree to a given total branch length.
tree.remove.node.labels

Removes internal node labels from a tree
tree.remove.leaf

Removes a single leaf from the tree and returns a copy.
tree.get.tag

tree.translate

Translates all labels in the tree based on a list of label mappings.
tree.node.with.label

Returns the index of the node with a given label.
tree.mean.path.length

Returns the mean root-to-tip path length of the tree. This is defined as the mean, across all leaves, of the total branch length from the root to the leaf.
tree.load.data

Loads a data.frame or CSV file into a tree as tags. Requires a 'label' column in the source data, which is used to merge rows in the dataset to labeled nodes in the tree.
tree.lengths.to.root

Returns a vector containing the root-to-tip branch length for each leaf in the tree.
tree.length.to.root

Returns the length from the tree root to the given node. The input node can either be input as a node index or a node label.
write.nhx

Writes the phylo object to disk in NHX format.
tree.max.length.to.root

Returns the maximum root-to-tip branch length in the tree. The root-to-tip branch length is calculated for each node, and the maximum value is returned.
tree.tags.to.labels

Converts all tags from a tree into NHX annotations and applies those annotations to each node's label.
tree.strip.branchlengths

Removes branch lengths from a tree