| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/get_subdendrograms.R |
| 3 |
\name{find_dendrogram} |
| 4 |
\alias{find_dendrogram} |
| 5 |
\title{Search for the sub-dendrogram structure composed of selected labels} |
| 6 |
\usage{ |
| 7 |
find_dendrogram(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 |
\value{ |
| 16 |
Either a sub-dendrogram composed of only members of selected_labels. |
| 17 |
If such a sub-dendrogram doesn't exist, the function returns NULL. |
| 18 |
} |
| 19 |
\description{ |
| 20 |
Given a dendrogram object, the function performs a recursive DFS algorithm to determine |
| 21 |
the sub-dendrogram which is composed of (exactly) all 'selected_labels'. |
| 22 |
} |
| 23 |
\examples{ |
| 24 |
|
| 25 |
\dontrun{ |
| 26 |
# define dendrogram object to play with: |
| 27 |
dend <- iris[, -5] \%>\% |
| 28 |
dist() \%>\% |
| 29 |
hclust() \%>\% |
| 30 |
as.dendrogram() \%>\% |
| 31 |
set("labels_to_character") \%>\% |
| 32 |
color_branches(k = 5) |
| 33 |
first.subdend.only <- names(cutree(dend, 4)[cutree(dend, 4) == 1]) |
| 34 |
sub.dend <- find_dendrogram(dend, first.subdend.only) |
| 35 |
# Plotting the result |
| 36 |
par(mfrow = c(1, 2)) |
| 37 |
plot(dend, main = "Original dendrogram") |
| 38 |
plot(sub.dend, main = "First subdendrogram") |
| 39 |
|
| 40 |
dend <- 1:10 \%>\% |
| 41 |
dist() \%>\% |
| 42 |
hclust() \%>\% |
| 43 |
as.dendrogram() \%>\% |
| 44 |
set("labels_to_character") \%>\% |
| 45 |
color_branches(k = 5) |
| 46 |
|
| 47 |
selected_labels <- as.character(1:4) |
| 48 |
sub_dend <- find_dendrogram(dend, selected_labels) |
| 49 |
plot(dend, main = "Original dendrogram") |
| 50 |
plot(sub_dend, main = "First subdendrogram") |
| 51 |
|
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
} |