Question: heatmap.2 RowSideColors ordering problem
gravatar for tospo
5.4 years ago by
United Kingdom
tospo50 wrote:

In R heatmap.2 I am supplying my own dendrogram and I want to annotate the columns with colors indicating the grouping of my samples.

My data is in DESeq2 objects, so I define a color mapping like this (rld is an rlog transformed DESeqDataSet)

sideCols=brewer.pal(12, "Set3")[ as.integer(colData(rld)[colnames(as.matrix(dist.rld)) ,"sample_group"]) ]

and clustering like this


then I draw the heatmap with this

heatmap.2( as.matrix(dist.rld), Rowv = as.dendrogram(hc), trace="none", scale="none", symm=T, RowSideColors=sideCols)

The problem is that the color vector for RowSideColors needs to be in the order in which the rows will appear. How do I get that information out of the dendrogram as.dendrogram(hc)?

I saw a comment here claiming that the order of the colors would be automatically adjusted according to the re-ordering of the rows/coloumns but I guess that will only happen if heatmap.2 does the clustering and not when you supply a ready-made dendrogram, right?

Thanks for your help!

================ EDIT: Problem solved  ==========

Sorry, my bad - turns out that the problem was with my input data. This does actually work with the code I have posted above and the colors are ordered correctly.



heatmap dendrogram R • 4.6k views
ADD COMMENTlink modified 5.4 years ago • written 5.4 years ago by tospo50
gravatar for tospo
5.4 years ago by
United Kingdom
tospo50 wrote:

Problems solved, see edit in OP

ADD COMMENTlink written 5.4 years ago by tospo50
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1150 users visited in the last hour