Question: heatmap.2 RowSideColors ordering problem
0
gravatar for tospo
4.5 years ago by
tospo40
United Kingdom
tospo40 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

dist.rld<-dist(t(assay(rld)))

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 • 3.8k views
ADD COMMENTlink modified 4.5 years ago • written 4.5 years ago by tospo40
1
gravatar for tospo
4.5 years ago by
tospo40
United Kingdom
tospo40 wrote:

Problems solved, see edit in OP

ADD COMMENTlink written 4.5 years ago by tospo40
Please log in to add an answer.

Help
Access

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