| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/get_subdendrograms.R |
| 3 |
\name{collapse_labels} |
| 4 |
\alias{collapse_labels} |
| 5 |
\title{Collapse a sub dendrogram of adjacent labels within a dend} |
| 6 |
\usage{ |
| 7 |
collapse_labels(dend, selected_labels, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{dend}{a dendrogram object} |
| 11 |
|
| 12 |
\item{selected_labels}{A character vector with the labels we expect to have |
| 13 |
in the sub-dendrogram. This doesn't have to be in the same order as in the dendrogram.} |
| 14 |
|
| 15 |
\item{...}{elipsis (passed to squash_dendrogram)} |
| 16 |
} |
| 17 |
\value{ |
| 18 |
Either the original dend. |
| 19 |
Or, if the labels properly are in the dend by each other, a dend with |
| 20 |
a squashed sub-dendrogram inside it. |
| 21 |
} |
| 22 |
\description{ |
| 23 |
Given a dendrogram object, and a set of labels that are in the same sub-dendrogram, |
| 24 |
the function performs a recursive DFS algorithm to determine |
| 25 |
the sub-dendrogram which is composed of (exactly) all 'selected_labels'. |
| 26 |
It then squashes this sub-dendrogram, and returns the original dendrogram with the squashed |
| 27 |
dendrogram with it. |
| 28 |
} |
| 29 |
\examples{ |
| 30 |
library("dendextend") |
| 31 |
|
| 32 |
set.seed(23235) |
| 33 |
ss <- sample(1:150, 5) |
| 34 |
|
| 35 |
# Getting the dend object |
| 36 |
dend25 <- iris[ss, -5] \%>\% |
| 37 |
dist() \%>\% |
| 38 |
hclust() \%>\% |
| 39 |
as.dendrogram() \%>\% |
| 40 |
set("labels", letters[1:5]) |
| 41 |
|
| 42 |
par(mfrow = c(1,4)) |
| 43 |
plot(dend25) |
| 44 |
plot(collapse_labels(dend25, c("d", "e"))) |
| 45 |
plot(collapse_labels(dend25, c("c", "d", "e"))) |
| 46 |
plot(collapse_labels(dend25, c("c", "d", "e"), squashed_original_height=TRUE)) |
| 47 |
} |