0

I recently learned how to make clustering plots in R, as detailed in my question found: here. So now I can make helpful plots, but there is one formatting feature that would really help... to be able to specify predefined groups of samples to be plotted in different colors.

For example, given the following very busy plot, I would like specific rows of the data matrix used to generate this plot to be plotted in specific colors, so I could see how well the dendrogram clustering fits my hypothesis regarding where the samples should be clustering.

Example plot without branches (samples) in predefined colors:

enter image description here

I made this plot with the following code:

un_exprs <- as.matrix(read.table("data.txt", header=TRUE, sep = "\t", row.names = 1, as.is=TRUE))
exprs <- t(un_exprs)
eucl_dist=dist(exprs,method = 'euclidean')
hie_clust=hclust(eucl_dist,method = 'complete')
plot(hie_clust)

All help is much appreciated!

UPDATE: My question is not the same as answered here: How to create a dendrogram with colored branches? That question sought to arbitrarily color the clusters/edges of a dendrogram. That is not what I want to do. I want every edge or label to be colored as determine by a predefined list, regardless of where on the dendrogram the edge appears.

Community
  • 1
  • 1
jake9115
  • 3,964
  • 12
  • 49
  • 78
  • Not the same question, they are looking to arbitrarily color clusters, not based on the identity of the edge. Please see my updated question addressing this point. Thanks! – jake9115 Jul 17 '15 at 07:25
  • 3
    I think the `dendextend` package does exactly what you want. Thanks! –  Jul 17 '15 at 07:27
  • @Pascal Thanks for the advice about dendextend, I took a look at it from the similar question, but it seems you have to specify the number of number of cluster (`Ex. k-5`) before plotting, meaning I need to color clusters, not individual edges. Or am I wrong? – jake9115 Jul 17 '15 at 07:39

0 Answers0