| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/highlight_branches.R |
| 3 |
\name{highlight_branches_col} |
| 4 |
\alias{highlight_branches_col} |
| 5 |
\alias{highlight_branches_lwd} |
| 6 |
\alias{highlight_branches} |
| 7 |
\title{Highlight a dendrogram's branches heights via color and line-width} |
| 8 |
\usage{ |
| 9 |
highlight_branches_col(dend, values = rev(viridis(1000, end = 0.9)), ...) |
| 10 |
|
| 11 |
highlight_branches_lwd(dend, values = seq(1, 10, length.out = 1000), ...) |
| 12 |
|
| 13 |
highlight_branches(dend, type = c("col", "lwd"), ...) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{dend}{a \link{dendrogram} tree (to be turned into a ggdend object)} |
| 17 |
|
| 18 |
\item{values}{the gradient of values to be used for each branch. |
| 19 |
The colors are based on the viridis pallette, and the line width is on the range of 1 to 10. |
| 20 |
These can be manually changed when using highlight_branches_col and highlight_branches_lwd |
| 21 |
respectively.} |
| 22 |
|
| 23 |
\item{...}{Currently ignored.} |
| 24 |
|
| 25 |
\item{type}{a character vector. Either "col", "lwd", or both. Based on |
| 26 |
whichever is chosen the dendrogram's branches will be updated.} |
| 27 |
} |
| 28 |
\value{ |
| 29 |
A modified \link{dendrogram}, with colors/line-width in the branches |
| 30 |
that are proportional to each branche's height (measured by its lower tip). |
| 31 |
} |
| 32 |
\description{ |
| 33 |
Highlights (update) the color (col) and/or line width (lwd) of each branch in |
| 34 |
a dendrogram based on it's node's height. |
| 35 |
This is a powerful pre-processing for a \link{tanglegram} plot of two dendrograms, as |
| 36 |
it emphasizes the toplogical structure of each tree (and hence, their similarity and differences). |
| 37 |
|
| 38 |
The colors are based on the viridis pallette, and the line width is on the range of 1 to 10. |
| 39 |
These can be manually changed when using highlight_branches_col and highlight_branches_lwd |
| 40 |
respectively. |
| 41 |
} |
| 42 |
\examples{ |
| 43 |
|
| 44 |
|
| 45 |
dat <- iris[1:20, -5] |
| 46 |
hca <- hclust(dist(dat)) |
| 47 |
hca2 <- hclust(dist(dat), method = "single") |
| 48 |
dend <- as.dendrogram(hca) |
| 49 |
dend2 <- as.dendrogram(hca2) |
| 50 |
|
| 51 |
par(mfrow = c(1, 3)) |
| 52 |
dend \%>\% |
| 53 |
highlight_branches_col() \%>\% |
| 54 |
plot(main = "Coloring branches") |
| 55 |
dend \%>\% |
| 56 |
highlight_branches_lwd() \%>\% |
| 57 |
plot(main = "Emphasizing line-width") |
| 58 |
dend \%>\% |
| 59 |
highlight_branches() \%>\% |
| 60 |
plot(main = "Emphasizing color\n and line-width") |
| 61 |
|
| 62 |
library(viridis) |
| 63 |
par(mfrow = c(1, 3)) |
| 64 |
dend \%>\% |
| 65 |
highlight_branches_col() \%>\% |
| 66 |
plot(main = "Coloring branches \n(default is reversed viridis)") |
| 67 |
dend \%>\% |
| 68 |
highlight_branches_col(viridis(100)) \%>\% |
| 69 |
plot(main = "It is better to use\nlighter colors in the leaves") |
| 70 |
dend \%>\% |
| 71 |
highlight_branches_col(rev(magma(1000))) \%>\% |
| 72 |
plot(main = "The magma color pallatte\n is also good") |
| 73 |
|
| 74 |
dl <- dendlist(dend, dend2) |
| 75 |
tanglegram(dl, |
| 76 |
sort = TRUE, common_subtrees_color_lines = FALSE, |
| 77 |
highlight_distinct_edges = FALSE, highlight_branches_lwd = FALSE |
| 78 |
) |
| 79 |
tanglegram(dl) |
| 80 |
tanglegram(dl, fast = TRUE) |
| 81 |
|
| 82 |
dl <- dendlist(highlight_branches(dend), highlight_branches(dend2)) |
| 83 |
tanglegram(dl, sort = TRUE, common_subtrees_color_lines = FALSE, highlight_distinct_edges = FALSE) |
| 84 |
|
| 85 |
dend \%>\% |
| 86 |
set("highlight_branches_col") \%>\% |
| 87 |
plot() |
| 88 |
|
| 89 |
dl <- dendlist(dend, dend2) \%>\% set("highlight_branches_col") |
| 90 |
tanglegram(dl, sort = TRUE, common_subtrees_color_lines = FALSE, highlight_distinct_edges = FALSE) |
| 91 |
|
| 92 |
|
| 93 |
# This is also useful for heatmaps |
| 94 |
# -------------------------- |
| 95 |
# library(dendextend) |
| 96 |
|
| 97 |
x <- as.matrix(datasets::mtcars) |
| 98 |
|
| 99 |
Rowv <- x \%>\% |
| 100 |
dist() \%>\% |
| 101 |
hclust() \%>\% |
| 102 |
as.dendrogram() \%>\% |
| 103 |
set("branches_k_color", k = 3) \%>\% |
| 104 |
set("highlight_branches_lwd") \%>\% |
| 105 |
ladderize() |
| 106 |
# rotate_DendSer(ser_weight = dist(x)) |
| 107 |
Colv <- x \%>\% |
| 108 |
t() \%>\% |
| 109 |
dist() \%>\% |
| 110 |
hclust() \%>\% |
| 111 |
as.dendrogram() \%>\% |
| 112 |
set("branches_k_color", k = 2) \%>\% |
| 113 |
set("highlight_branches_lwd") \%>\% |
| 114 |
ladderize() |
| 115 |
# rotate_DendSer(ser_weight = dist(t(x))) |
| 116 |
|
| 117 |
library(gplots) |
| 118 |
heatmap.2(x, Rowv = Rowv, Colv = Colv) |
| 119 |
} |
| 120 |
\seealso{ |
| 121 |
\link{set}, \link{color_branches}, \link{get_branches_heights}, |
| 122 |
\link[viridis]{viridis} |
| 123 |
} |