Creates dendrogram plot using ggplot.

Share:

Description

Several functions for creating a dendrogram plot using ggplot2.
The core process is to transform a dendrogram into a ggdend object using as.ggdend,
and then plot it using ggplot. These two steps can be done in one command with either the function
ggplot or ggdend.

The reason we want to have as.ggdend (and not only ggplot.dendrogram), is (1) so that you could
create your own mapping of ggdend and, (2) since as.ggdend might be slow for large trees,
it is probably better to be able to run it only once for such cases.

A ggdend class object is a list with 3 componants: segments, labels, nodes.
Each one contains the graphical parameters from the original dendrogram, but in a tabular form that
can be used by ggplot2+geom_segment+geom_text to create a dendrogram plot.

Arguments

The type of plot, indicating the shape of the dendrogram. "rectangle" will draw
rectangular lines, while "triangle" will draw triangular lines.

edge.root

currently ignored. One day it might do the following: logical; if true, draw an edge to the root node.

data

a ggdend class object.

segments

a logical (TRUE) if to plot the segments (branches).

labels

a logical (TRUE) if to plot the labels.

offset_labels

a numeric value to offset the labels from the leaves

nodes

a logical (TRUE) if to plot the nodes (points).

horiz

a logical (TRUE) indicating if the dendrogram should be drawn horizontally or not.

theme

the ggplot2 theme to use (default is theme_dendro, can also be NULL
for the default ggplot2 theme)

Details

prepare.ggdend is used by plot.ggdend to take the ggdend object
and prepare it for plotting. This is because the defaults of various parameters in dendrogram's
are not always stored in the object itself, but are built-in into the plot.dendrogram function.
For example, the color of the labels is not (by default) specified in the dendrogram (only if we change it
from black to something else). Hence, when taking the object into a different plotting engine (say ggplot2), we
want to prepare the object by filling-in various defaults.
This function is autmatically invoked within the plot.ggdend function. You would probably use
it only if you'd wish to build your own ggplot2 mapping.

Value

as.ggdend - returns an object of class ggdend which is a list with 3 componants: segments, labels, nodes.
Each one contains the graphical parameters from the original dendrogram, but in a tabular form that
can be used by ggplot2+geom_segment+geom_text to create a dendrogram plot.

prepare.ggdend - a ggdend object (after filling it with various default values)

ggplot.ggdend - a ggplot object

Author(s)

Tal Galili, using code modified from Andrie de Vries

Source

These are extended versions of the functions ggdendrogram, dendro_data (and the hidden dendrogram_data)
from Andrie de Vries's ggdendro package. The motivation for this fork is the need to add more graphical parameters
to the plotted tree. This required a strong mixter of functions from ggdendro and dendextend (to the point that
it seemed better to just fork the code into its current form)