-
Notifications
You must be signed in to change notification settings - Fork 11
/
README.Rmd
90 lines (63 loc) · 3.07 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
output: github_document
format: gfm
default-image-extension: ""
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ggdendro <img src='man/figures/logo.png' align="right" height="139" />
Provides functions for creating dendrograms and tree plots using `ggplot2`.
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/ggdendro)](https://CRAN.R-project.org/package=ggdendro)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/ggdendro)](http://www.r-pkg.org/pkg/ggdendro)
[![R-CMD-check](https://github.com/andrie/ggdendro/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/andrie/ggdendro/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/andrie/ggdendro/branch/main/graph/badge.svg)](https://app.codecov.io/gh/andrie/ggdendro?branch=main)
[![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive)
<!-- badges: end -->
The `ggdendro` package offers a generic function to extract data and text from the various clustering models:
* `dendro_data()` extracts cluster information from the model object, e.g. cluster allocation, line segment data or label data.
The `dendro_data` object has methods for the following classes:
* `tree`
* `hclust`
* `dendrogram`
* `rpart`
These methods create an object of class `dendro`, which is essentially a list of data frames. To extract the relevant data frames from the list, use the three accessor functions:
* `segment()` for the line segment data
* `label()` for the text for each end segment
* `leaf_label()` for the leaf labels of a tree diagram
The results of these functions can then be passed to `ggplot()` for plotting.
## Examples
```{r}
library(ggplot2)
library(ggdendro)
hc <- hclust(dist(USArrests), "ave")
hcdata <- dendro_data(hc, type = "rectangle")
ggplot() +
geom_segment(data = segment(hcdata),
aes(x = x, y = y, xend = xend, yend = yend)
) +
geom_text(data = label(hcdata),
aes(x = x, y = y, label = label, hjust = 0),
size = 3
) +
coord_flip() +
scale_y_reverse(expand = c(0.2, 0))
### demonstrate plotting directly from object class hclust
ggdendrogram(hc)
ggdendrogram(hc, rotate = TRUE)
### demonstrate converting hclust to dendro using dendro_data first
hcdata <- dendro_data(hc)
ggdendrogram(hcdata, rotate = TRUE) +
labs(title = "Dendrogram in ggplot2")
```
# Use `dendextend` instead
Most of the functionality in `ggdendro` is included in the excellent `dendextend` package. In most cases, if you need additional functionality, please use the `dendextend` package instead.
The `ggdendro` package will only get minimal maintenance in future.
Refer to <https://cran.r-project.org/web/packages/dendextend/index.html>