plot_tree: Visualize the Tree Structure

View source: R/plot_functions.R

plot_treeR Documentation

Visualize the Tree Structure

Description

This function plots a tree structure. The tree structure can be represented by a variety of object formats: dendrogram, hclust or a list (hc_list).

Usage

plot_tree(tree = NULL, iflabel = FALSE, labels = NULL)

Arguments

tree

An object encoding the tree structure. Can be one of three formats: (1) an hclust object (if tree is binary), (2) a dendrogram, or (3) a generalization of an hclust object to the case of non-binary trees, which we call an hc_list object. An hc_list object is a list of length-num_interior_nodes where the ith item in the list contains the child nodes of the ith node in the tree. The negative values in the list indicate leaf nodes.

iflabel

A boolean variable indicating whether leaves should be labeled.

labels

A vector of length-n-leaf of labels corresponding to each leaf.

Examples

## Example 1: Plot an hc object
hc = hclust(dist(USArrests), "ave")
labels = rownames(USArrests)[hc$order]
plot_tree(tree = hc, iflabel = TRUE)
## Example 2: Plot a dendrogram object
dend = as.dendrogram(hc)
plot_tree(tree = dend, iflabel = TRUE)
## Example 3: Plot a hc_list object
dah = dend_as_hclist(dend)
labels = attr(dah, "leaf_labels")
plot_tree(tree = dah, iflabel = TRUE, labels = labels)

simone0628/hat documentation built on June 1, 2024, 9 a.m.