我正在尝试将此树状图分为 3 组:(T24、T1、T17 等)、(T12、T15、T6 等)和(T2、T8、T3、T9)
我曾尝试使用 cutree(hc, k=3, h=400) ,但它继续制作相同的组。任何帮助是极大的赞赏。这是我的代码。
#temps must have date/time as column headers, not row headers
load(temps)
distMatrix <- dist(temps)
#create label colors
labelColors = c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33")
# cut dendrogram in 3 clusters
clusMember = cutree(hc, k=3, h=400)
colLab <- function(n) {
if (is.leaf(n)) {
a <- attributes(n)
labCol <- labelColors[clusMember[which(names(clusMember) == a$label)]]
attr(n, "nodePar") <- c(a$nodePar, lab.col = labCol)
}
n
}
hcd = as.dendrogram(hc)
clusDendro = dendrapply(hcd, colLab)
plot(clusDendro, main = "Cluster Analysis")