Hi I would like to create a dendrogram in R which has colored branches, like the one shown below. <http://r.789695.n4.nabble.com/file/n4672993/dendrogram.png> So far I used following commands to create a standard dendrogram: 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 How should I modify this code to obtain a desired result ? Thanks in advance for your help. -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-a-dendrogram-with-colored-branches-tp4672993.html Sent from the R help mailing list archive at Nabble.com.
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20130803/633e2516/attachment.pl>
Gregory Jefferis
2013-Aug-03 18:46 UTC
[R] How to create a dendrogram with colored branches
On 3 Aug 2013, at 16:47, beginner wrote:> d <- dist(as.matrix(data[,29])) # find distance matrix > hc <- hclust(d) # apply hirarchical clustering > plot(hc,labels=data[,1], main="", xlab="") # plot the dendrogramYou haven't given a reproducible example (data is undefined), so we can't help you with your specific code. But what you want can be achieved with the package dendroextras on CRAN. install.packages("dendroextras") library(dendroextras) hc=hclust(dist(USArrests), "ave") # nb you have to cut your dendrogram by number of groups (k) d5=colour_clusters(hc,k=5) plot(d5) #... or by height (h) d5=colour_clusters(hc,h=75) plot(d5) ?colour_clusters for more details. Best wishes, Greg Jefferis. -- Gregory Jefferis, PhD Division of Neurobiology MRC Laboratory of Molecular Biology Francis Crick Avenue Cambridge Biomedical Campus Cambridge, CB2 OQH, UK http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis http://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2 http://flybrain.stanford.edu