<p>Hi all,</p>

<p>I am having a hard time to extract the corresponding subgroup members in the heatmap generated by heatmap.2 in gplots.
I have looked here: <a href='http://stackoverflow.com/questions/15388082/understanding-heatmap-dendogram-clustering-in-r'>http://stackoverflow.com/questions/15388082/understanding-heatmap-dendogram-clustering-in-r</a>
and <a href='http://stackoverflow.com/questions/11489696/how-to-know-about-group-information-in-cluster-analysis-hierarchical'>http://stackoverflow.com/questions/11489696/how-to-know-about-group-information-in-cluster-analysis-hierarchical</a>
and here <a href='https://stat.ethz.ch/pipermail/bioconductor/2007-December/020521.html'>https://stat.ethz.ch/pipermail/bioconductor/2007-December/020521.html</a></p>

<p>I have a matrix m, the heatmap can be generated by</p>

<p>heatmap.2(m, colv=FALSE, dendrogram= "row", trace="none")</p>

<p>it gave me very good looking heatmap, now I want to extract the subgroup members.</p>

<p>I know I can use hclust and cutree to extract the information:</p>

<p>hc.rows&lt;- hclust(dist(m))</p>

<p>plot(hc.rows)   # it gives me just the dendrogram, and it looks the same as the dendrogram appeared in the heatmap, only differ  in the order. it seems to me the order is reversed.</p>

<p>I can cut the tree based on either the number of group (k), or the height (h)</p>

<p>ct&lt;- cutree(hc.rows, h=10)  # it gives me 6 groups</p>

<p>rect.hclust(hc.rows, h=10)  # draw red rectangles to mark the subgroups</p>

<p>table(ct)</p>

<p>ct</p>

<p>1   2   3   4   5   6 </p>

<p>196 248 294 119  42   4</p>

<p>I can get the labels of each row, and the assigned the group number by:</p>

<p>tableclust&lt;- data.frame(m,ct)</p>

<p>my question is that how do I map the cluster number here back to the dendrogram? 
cluster 6 has 4 members, but it looks like to me cluster 6 appears in the most left of the dendrogram, cluster 5 has 42 members, it appears in the second most left (based on the width of the red rectangle in the dendrogram), cluster 4 has 119 members, but it appears not next to cluster 5....</p>

<p><img src='http://i43.tinypic.com/2hhktw9.png' alt='enter image description here' /></p>

<p>I am confused.....</p>

<p>Thanks for your advice.</p>

<p>Tommy Tang</p>

use `svg(width=50)` option. Increase it for bigger width. https://www.biostars.org/p/49786/