Debian Codegraph @

man/dendro_data.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/dendro_data.R, R/dendrogram.R
3 \name{dendro_data}
4 \alias{dendro_data}
5 \alias{dendro_data.default}
6 \alias{dendro_data.dendrogram}
7 \alias{dendro_data.hclust}
8 \alias{dendro_data.twins}
9 \title{Extract cluster data from a model into a list of data frames.}
10 \usage{
11 dendro_data(model, ...)
12
13 \method{dendro_data}{default}(model, ...)
14
15 \method{dendro_data}{dendrogram}(model, type = c("rectangle", "triangle"), ...)
16
17 \method{dendro_data}{hclust}(model, type = c("rectangle", "triangle"), ...)
18
19 \method{dendro_data}{twins}(model, type = c("rectangle", "triangle"), ...)
20 }
21 \arguments{
22 \item{model}{object of class "dendrogram", e.g. the output of as.dendrogram()}
23
24 \item{...}{ignored}
25
26 \item{type}{The type of plot, indicating the shape of the dendrogram.
27 "rectangle" will draw rectangular lines, while "triangle" will draw
28 triangular lines.}
29 }
30 \value{
31 a list of data frames that contain the data appropriate to each
32 cluster model
33
34 A list with components:
35 \item{segments}{Line segment data}
36 \item{labels}{Label data}
37 }
38 \description{
39 This function provides a generic mechanism to extract relevant plotting data,
40 typically line segments and labels, from a variety of cluster models.
41
42 Extract line segment and label data from \code{\link[stats:dendrogram]{stats::dendrogram()}} or
43 \code{\link[stats:hclust]{stats::hclust()}} object. The resulting object is a list of data frames
44 containing line segment data and label data.
45 }
46 \details{
47 For \code{\link[stats:dendrogram]{stats::dendrogram()}} and \code{tree::tree()} models, extracts line segment
48 data and labels.
49 }
50 \examples{
51 require(ggplot2)
52
53 ### Demonstrate dendro_data.dendrogram
54
55 model <- hclust(dist(USArrests), "ave")
56 dendro <- as.dendrogram(model)
57
58 # Rectangular lines
59 ddata <- dendro_data(dendro, type = "rectangle")
60 ggplot(segment(ddata)) +
61 geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) +
62 coord_flip() +
63 scale_y_reverse(expand = c(0.2, 0)) +
64 theme_dendro()
65
66 # Triangular lines
67 ddata <- dendro_data(dendro, type = "triangle")
68 ggplot(segment(ddata)) +
69 geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) +
70 theme_dendro()
71
72 # Demonstrate dendro_data.hclust
73
74 require(ggplot2)
75 hc <- hclust(dist(USArrests), "ave")
76
77 # Rectangular lines
78 hcdata <- dendro_data(hc, type = "rectangle")
79 ggplot(segment(hcdata)) +
80 geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) +
81 coord_flip() +
82 scale_y_reverse(expand = c(0.2, 0)) +
83 theme_dendro()
84
85 # Triangular lines
86 hcdata <- dendro_data(hc, type = "triangle")
87 ggplot(segment(hcdata)) +
88 geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) +
89 theme_dendro()
90 ### Demonstrate the twins of agnes and diana, from package cluster
91
92 if (require(cluster)) {
93 model <- agnes(votes.repub, metric = "manhattan", stand = TRUE)
94 dg <- as.dendrogram(model)
95 ggdendrogram(dg)
96 }
97
98
99 if (require(cluster)) {
100 model <- diana(votes.repub, metric = "manhattan", stand = TRUE)
101 dg <- as.dendrogram(model)
102 ggdendrogram(dg)
103 }
104 }
105 \seealso{
106 There are several implementations for specific cluster algorithms:
107 \itemize{
108 \item \code{\link[=dendro_data.hclust]{dendro_data.hclust()}}
109 \item \code{\link[=dendro_data.dendrogram]{dendro_data.dendrogram()}}
110 \item \code{\link[=dendro_data.tree]{dendro_data.tree()}}
111 \item \code{\link[=dendro_data.rpart]{dendro_data.rpart()}}
112 }
113
114 To extract the data for line segments, labels or leaf labels use:
115 \itemize{
116 \item \code{\link[=segment]{segment()}}: the line segment data
117 \item \code{\link[=label]{label()}}: the text for each end segment
118 \item \code{\link[=leaf_label]{leaf_label()}}: the leaf labels of a tree diagram
119 }
120
121 \code{\link[=ggdendrogram]{ggdendrogram()}}
122
123 Other dendro_data methods:
124 \code{\link{dendro_data.rpart}()},
125 \code{\link{dendro_data.tree}()},
126 \code{\link{dendrogram_data}()},
127 \code{\link{rpart_labels}()}
128
129 Other dendrogram/hclust functions:
130 \code{\link{dendrogram_data}()}
131 }
132 \concept{dendro_data methods}
133 \concept{dendrogram/hclust functions}