| 1 |
## ----echo = FALSE, message = FALSE, warning=FALSE----------------------------- |
| 2 |
library(dendextend) |
| 3 |
library(knitr) |
| 4 |
knitr::opts_chunk$set( |
| 5 |
cache = TRUE, |
| 6 |
dpi = 75, |
| 7 |
fig.width = 6, fig.height = 6, |
| 8 |
# comment = "#>", |
| 9 |
tidy = FALSE) |
| 10 |
|
| 11 |
# https://stackoverflow.com/questions/24091735/why-pandoc-does-not-retrieve-the-image-file |
| 12 |
# < ! -- rmarkdown v1 --> |
| 13 |
|
| 14 |
|
| 15 |
## ----------------------------------------------------------------------------- |
| 16 |
library(dendextend) # |
| 17 |
|
| 18 |
## ----------------------------------------------------------------------------- |
| 19 |
dend <- c(1:5) %>% dist %>% hclust("ave") %>% as.dendrogram |
| 20 |
|
| 21 |
## ----------------------------------------------------------------------------- |
| 22 |
plot(dend) |
| 23 |
|
| 24 |
## ----------------------------------------------------------------------------- |
| 25 |
labels(dend) |
| 26 |
labels(dend) <- c("A", "B", "extend", "dend", "C") |
| 27 |
labels(dend) |
| 28 |
|
| 29 |
## ----------------------------------------------------------------------------- |
| 30 |
labels_colors(dend) |
| 31 |
labels_colors(dend) <- rainbow(5) |
| 32 |
labels_colors(dend) |
| 33 |
plot(dend) |
| 34 |
|
| 35 |
## ----------------------------------------------------------------------------- |
| 36 |
cutree(dend, k = 2) |
| 37 |
dend <- color_branches(dend, k = 2) |
| 38 |
plot(dend) |
| 39 |
|
| 40 |
## ----------------------------------------------------------------------------- |
| 41 |
dend2 <- sort(dend) |
| 42 |
plot(dend2) |
| 43 |
|
| 44 |
## ----------------------------------------------------------------------------- |
| 45 |
tanglegram( dend, dend2 ) |
| 46 |
|
| 47 |
## ----------------------------------------------------------------------------- |
| 48 |
cor_cophenetic( dend, dend2 ) |
| 49 |
|
| 50 |
## ----------------------------------------------------------------------------- |
| 51 |
library(ggplot2) |
| 52 |
ggplot(dend) |
| 53 |
|
| 54 |
## ----------------------------------------------------------------------------- |
| 55 |
|
| 56 |
# library(plotly) |
| 57 |
# set_credentials_file(...) |
| 58 |
# you'll need to get it from here: https://plot.ly/ggplot2/getting-started/ |
| 59 |
|
| 60 |
# ggplot(dend) |
| 61 |
# py <- plotly() |
| 62 |
# py$ggplotly() |
| 63 |
|
| 64 |
|