How to change dendrogram labels in r

为君一笑 提交于 2019-12-03 14:29:53

In the hclust object you've created, cl, you have an element named "order" that contains the order in which the elements are in the dendrogram.

If you want to change the labels, you need to put the new labels in the same order (cl$order), so the "new" dendrogram is right:

df$column2[cl$order]

The dendextend package allows you to directly update dendrograms (as well as hclust), by using the following:

x <- c(1:5)
dend <- as.dendrogram(hclust(dist(x)))

if(!require(dendextend)) install.packages("dendextend")
library("dendextend")

labels(dend)
labels(dend) <- c(21:25)
labels(dend)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!