plothc: Color 'plot.hclust'

View source: R/plot.R

plothcR Documentation

Color plot.hclust

Description

Plot an hclust object with colored labels.

Usage

plothc(hc, labels = hc$labels, col = as.factor(labels), hang = 0.1, ...)

Arguments

hc

an hclust object

labels

a character vector of labels for the leaves of the tree

col

a vector of valid colors for labels

hang

the fraction of the plot height by which labels should hang below the rest of the plot; a negative value will cause labels to hang down from 0

...

additional arguments passed to plot.hclust

Author(s)

Eva KF Chan, https://github.com/ekfchan/evachan.org-Rscripts, modifications by Robert Redd

Examples

hc <- hclust(dist(iris[, 1:4]))
plothc(hc)
plothc(hc, labels = iris$Species, col = as.numeric(iris$Species))


## add features below leaves
plothc(hc, col = iris$Species, xlab = '', sub = '')

set.seed(1)
mat <- matrix(rep(as.numeric(iris$Species), 3), 3)
mat[sample(length(mat), length(mat) / 2)] <- NA
mat <- sort_matrix(mat)[3:1, ]
shift <- c(0.5, 6)
rect(col(mat) - shift[1], row(mat) - shift[2], col(mat) + shift[1],
     row(mat) - shift[2] + 0.5, col = mat, xpd = NA, border = 'white')


raredd/rawr documentation built on Feb. 25, 2025, 1:48 p.m.