heatmap.2 RowSideColors ordering problem
1
0
Entering edit mode
9.7 years ago
tospo ▴ 50

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/columns 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.

dendrogram R heatmap • 6.8k views
ADD COMMENT
1
Entering edit mode
9.7 years ago
tospo ▴ 50

Problems solved, see edit in OP

ADD COMMENT

Login before adding your answer.

Traffic: 1716 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6