plot_aggregation: Visualize Aggregation on the Tree

View source: R/plot_functions.R

plot_aggregationR Documentation

Visualize Aggregation on the Tree

Description

This function plots a tree structure with branches and leaves colored by group memberships. The tree structure can be represented by a variety of object formats: dendrogram, hclust or a a list (hc_list). The aggregation is determined by a vector corresponding to each interior nodes

Usage

plot_aggregation(rejections, iflabel = FALSE, labels = NULL, tree = NULL)

Arguments

rejections

A vector of length-num_interior_nodes indicating if each node is rejected. When coloring with true aggregation, this vector indicate whether each interior node is a non-null node.

iflabel

A boolean variable indicating whether leaves should be labeled.

labels

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

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.

Examples

## Example 1: Plot an hc object
hc = hclust(dist(USArrests), "ave")
labels = rownames(USArrests)[hc$order]
plot_aggregation(rejections = c(rep(FALSE, 45), rep(TRUE, 4)), iflabel = TRUE, tree = hc)


## Example 2: Plot a dendrogram object
hc = hclust(dist(USArrests), "ave")
dend = as.dendrogram(hc)
plot_aggregation(rejections = c(rep(FALSE, 45), rep(TRUE, 4)), iflabel = TRUE, tree = dend)

## Example 3: Plot a hc_list object
hc = hclust(dist(USArrests), "ave")
dend = as.dendrogram(hc)
dah = dend_as_hclist(dend)
labels = attr(dah, "leaf_labels")
plot_aggregation(rejections = c(rep(FALSE, 45), rep(TRUE, 4)), iflabel = TRUE, labels = labels, tree = dah)

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