Learn R Programming

ggdendro (version 0.1-12)

dendro_data.dendrogram: Extract line segment and label data from dendrogram or hclust object.

Description

Extract line segment and label data from dendrogram or hclust object. Results are stored in a list of data frames containing line segment data and label data.

Usage

## S3 method for class 'dendrogram':
dendro_data(model,
    type = c("rectangle", "triangle"), ...)

Arguments

model
object of class "dendrogram", e.g. the output of as.dendrogram()
type
The type of plot, indicating the shape of the dendrogram. "rectangle" will draw rectangular lines, while "triangle" will draw triangular lines.
...
ignored

Value

  • A list with the following elements:
  • segmentsLine segment data
  • labelsLabel data

See Also

ggdendrogram Other dendro_data methods: dendro_data.tree, dendrogram_data Other dendrogram/hclust functions: dendrogram_data

Examples

Run this code
require(ggplot2)
#
# Demonstrate dendro_data.dendrogram
#
hc <- hclust(dist(USArrests), "ave")
dhc <- as.dendrogram(hc)
# Rectangular lines
ddata <- dendro_data(dhc, type="rectangle")
ggplot(segment(ddata)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) +
		coord_flip() + scale_y_reverse(expand=c(0.2, 0)) + theme_dendro()
# Triangular lines
ddata <- dendro_data(dhc, type="triangle")
ggplot(segment(ddata)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + theme_dendro()
#
# Demonstrate dendro_data.hclust
#
require(ggplot2)
hc <- hclust(dist(USArrests), "ave")
# Rectangular lines
hcdata <- dendro_data(hc, type="rectangle")
ggplot(segment(hcdata)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) +
   coord_flip() + scale_y_reverse(expand=c(0.2, 0)) + theme_dendro()
# Triangular lines
hcdata <- dendro_data(hc, type="triangle")
ggplot(segment(hcdata)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) +
  theme_dendro()

Run the code above in your browser using DataLab