[R] How to create a dendrogram with colored branches
Gregory Jefferis
jefferis at gmail.com
Sat Aug 3 20:46:08 CEST 2013
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 dendrogram
You 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
More information about the R-help
mailing list