Change Dendrogram leaves

后端 未结 3 1198
醉话见心
醉话见心 2020-12-15 12:45

I want to modify the properties of the leaves in a dendrogram produced from plot of an hclust object. Minimally, I want to change the colors, but any help you can provide w

3条回答
  •  难免孤独
    2020-12-15 13:20

    Here is a solution for this question using a new package called "dendextend", built exactly for this sort of thing.

    You can see many examples in the presentations and vignettes of the package, in the "usage" section in the following URL: https://github.com/talgalili/dendextend

    Here is the solution for this question:

    # define dendrogram object to play with:
    dend <- as.dendrogram(hclust(dist(USArrests[1:3,]), "ave"))
    # loading the package
    install.packages('dendextend') # it is now on CRAN
    library(dendextend)# let's add some color:
    labels_colors(dend) <- 2:4
    labels_colors(dend)
    plot(dend)
    

    enter image description here

提交回复
热议问题