Learn R Programming

dendextend (version 1.1.2)

color_labels: Color dend's labels according to sub-clusters

Description

This function is for dendrogram and hclust objects. This function colors tree's labels. The groups will be defined by a call to cutree using the k or h parameters. If col is a color vector with a different length than the number of clusters (k) - then a recycled color vector will be used.

Usage

color_labels(dend, k = NULL, h = NULL, labels, col,
  warn = dendextend_options("warn"), ...)

Arguments

dend
A dendrogram or hclust tree object
k
number of groups (passed to cutree)
h
height at which to cut tree (passed to cutree)
labels
character vecotor. If not missing, it overrides k and h, and simply colors these labels in the tree based on "col" parameter.
col
Function or vector of Colors. By default it tries to use rainbow_hcl from the colorspace package. (with parameters c=90 and l=50). If colorspace is not available, It will fall
warn
logical (default from dendextend_options("warn") is FALSE). Set if warning are to be issued, it is safer to keep this at TRUE, but for keeping the noise down, the default is FALSE. (in case h/k/labels are not supplied, or if col is too short)
...
ignored.

Value

  • a tree object of class dendrogram.

source

This function is in the style of color_branches, and based on labels_colors.

See Also

cutree,dendrogram, hclust, labels_colors, color_branches, assign_values_to_leaves_edgePar

Examples

Run this code
hc <- hclust(dist(USArrests), "ave")
dend <- as.dendrogram(hc)
dend=color_labels(dend,5, col = c(3,1,1,4,1))
dend=color_branches(dend,5, col = c(3,1,1,4,1))
plot(dend) # selective coloring of branches AND labels :)

# coloring some labels, based on label names:
dend=color_labels(dend,col = "red", labels = labels(dend)[c(4,16)])
plot(dend) # selective coloring of branches AND labels :)

d5=color_branches(dend,5)
plot(d5)
d5g=color_branches(dend,5,groupLabels=TRUE)
plot(d5g)
d5gr=color_branches(dend,5,groupLabels=as.roman)
plot(d5gr)

Run the code above in your browser using DataLab