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.
color_labels(
dend,
k = NULL,
h = NULL,
labels,
col,
warn = dendextend_options("warn"),
...
)
This function is in the style of color_branches
, and
based on labels_colors
.
A dendrogram
or hclust
tree object
number of groups (passed to cutree
)
height at which to cut tree (passed to cutree
)
character vecotor. If not missing, it overrides k and h, and simply colors these labels in the tree based on "col" parameter.
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 back on the rainbow function.
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.
a tree object of class dendrogram.
if (FALSE) { # \dontrun{
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)
} # }