On Fri, Apr 25, 2014 at 6:35 PM, chris Jhon <cjhon...@gmail.com> wrote: > Hi, > > I am using hclust and cutree to cluster a data frame y and cut it into few > clusters as follows > > y > V1 V2 V3 V4 > A 1 2 3 4 > B 5 6 7 8 > C 9 10 11 12 > D 13 14 15 16 > E 17 18 19 20 >> clu<-hclust(dist(y),method="complete") > clu<-hclust(dist(y),method="complete") >> clu > Call: > hclust(d = dist(y), method = "complete") > Cluster method : complete > Distance : euclidean > Number of objects: 5 >> plot(clu) >> ct<-cutree(clu,k=3) >> rect.hclust(clu,3,border="red") >> ct > A B C D E > 1 1 2 2 3 > The question is how to plot the cluster number on the dendrogram plot?
Package WGCNA (which I maintain) contains the function plotDendroAndColors that allows you to indicate (multiple) clusters under a dendrogram by colors, for example as in this image: http://labs.genetics.ucla.edu/horvath/CoexpressionNetwork/BranchCutting/Example-Dendrogram-10.png In the simplest use, you could call it as plotDendroAndColors(clu, ct, "Clusters", main = "My clusters") It will show cluster 1 as black, 2 as red etc. If you have more clusters than colors in the standard pallette (which only contains 8 different colors), you can use plotDendroAndColors(clu, labels2colors(ct), "Clusters", main = "My clusters") Function labels2colors converts integer numeric labels to discrete colors; the color sequence used by labels2colors can be seen by typing standardColors() Hope this helps, Peter ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.