I would like to create a dendrogram in R which has colored branches, like the one shown below.
到目前为止,我使用以下命令来创建标准树状图:
d <- dist(as.matrix(data[,29])) # find distance matrix
hc <- hclust(d) # apply hirarchical clustering
plot(hc,labels=data[,1], main="", xlab="") # plot the dendrogram
我应该如何修改此代码以获得所需的结果?
在此先感谢您的帮助。
你可以使用树状延伸 https://github.com/talgalili/dendextend包,旨在完成以下任务:
# install the package:
if (!require('dendextend')) install.packages('dendextend'); library('dendextend')
## Example:
dend <- as.dendrogram(hclust(dist(USArrests), "ave"))
d1=color_branches(dend,k=5, col = c(3,1,1,4,1))
plot(d1) # selective coloring of branches :)
d2=color_branches(d1,k=5) # auto-coloring 5 clusters of branches.
plot(d2)
# More examples are in ?color_branches
您可以在包的演示文稿和插图中看到许多示例,位于以下 URL 的“用法”部分:https://github.com/talgalili/dendextend https://github.com/talgalili/dendextend
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)