jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.29k stars 225 forks source link

Row order of annotation not correct #352

Closed endrebak closed 5 years ago

endrebak commented 5 years ago

Hi and thanks for this great package.

I have a question about the order of my row_annotation.

I want to map from sample names to groups. For example fetal_placenta belongs to the group Other, but in the graph below it has the color of Neurosph.

Screenshot 2019-09-04 at 14 03 20

When I print the vector I use for row annotations, it looks like this:


                                                       Fetal_Adrenal_Gland
                                                                   "Other"
                                                            Fetal_Placenta
                                                                   "Other"
                                                               Adult_Liver
                                                                   "Other"
                                                                  Pancreas
                                                                   "Other"
                                                                      Lung
                                                                   "Other"
                                                                    Spleen
                                                                   "Other"

so my mapping vector is correct.

This is how I create my mapping vector and plot the heatmap:

row_annotation = as.data.frame(tg$Group)
row_annotation = as.character(unlist(row_annotation))
names(row_annotation) = as.character(tg$Tissue)
annotation = rowAnnotation(Groups=row_annotation)
Heatmap(m, cluster_columns=FALSE, use_raster=FALSE, right_annotation=annotation)

Do you have any idea what I might be doing wrong? Thanks :)

jokergoo commented 5 years ago

Have you checked whether the order of matrix rows and your annotations have the same order?

try:

head(rownames(m))
head(row_annotation)

Are the two outputs the same?

endrebak commented 5 years ago

That was my error. I thought ComplexHeatmap used the names of the annotation vector to find the correct mapping. This is because I cluster and therefore reorder the rows. But it seems like as long as the annotation vector is the same order as the input matrix everything works - which is very convenient!

My mistake and thanks again for this great library.