Learn R Programming

dendextend (version 0.14.2)

color_labels: Color tree'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(tree, k = NULL, h = NULL, labels, col, warn = FALSE, ...)

Arguments

tree
A dendrogram or hclust tree object
k
number of groups (passed to cutree)
h
height at which to cut tree (passed to cutree)
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
labels
character vecotor. If not missing, it overrides k and h, and simply colors these labels in the tree based on "col" parameter.
warn
logical (FALSE). Should warning be issued? (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

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