| 1 |
require(ggplot2) |
| 2 |
|
| 3 |
### Demonstrate dendro_data.dendrogram |
| 4 |
|
| 5 |
model <- hclust(dist(USArrests), "ave") |
| 6 |
dendro <- as.dendrogram(model) |
| 7 |
|
| 8 |
# Rectangular lines |
| 9 |
ddata <- dendro_data(dendro, type = "rectangle") |
| 10 |
ggplot(segment(ddata)) + |
| 11 |
geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) + |
| 12 |
coord_flip() + |
| 13 |
scale_y_reverse(expand = c(0.2, 0)) + |
| 14 |
theme_dendro() |
| 15 |
|
| 16 |
# Triangular lines |
| 17 |
ddata <- dendro_data(dendro, type = "triangle") |
| 18 |
ggplot(segment(ddata)) + |
| 19 |
geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) + |
| 20 |
theme_dendro() |
| 21 |
|
| 22 |
# Demonstrate dendro_data.hclust |
| 23 |
|
| 24 |
require(ggplot2) |
| 25 |
hc <- hclust(dist(USArrests), "ave") |
| 26 |
|
| 27 |
# Rectangular lines |
| 28 |
hcdata <- dendro_data(hc, type = "rectangle") |
| 29 |
ggplot(segment(hcdata)) + |
| 30 |
geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) + |
| 31 |
coord_flip() + |
| 32 |
scale_y_reverse(expand = c(0.2, 0)) + |
| 33 |
theme_dendro() |
| 34 |
|
| 35 |
# Triangular lines |
| 36 |
hcdata <- dendro_data(hc, type = "triangle") |
| 37 |
ggplot(segment(hcdata)) + |
| 38 |
geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) + |
| 39 |
theme_dendro() |