How do I add a colour annotation bar to the heatmap generated by DoHeatmap function of Seurat v2? I am using Seurat v2 for professional reasons (I am aware of the availablity of Seurat v3). I am clustering and analysing single cell RNA seq data. How do I add a coloured annotation bar to the heatmap generated by the DoHeatmap function from Seurat v2? I want to be able to demarcate my cluster numbers on the heatmap over a coloured annotation bar. I want to have the an image like this:

 (taken from Satija V3 tutorial).

My original code:

library(Seurat)
DoHeatmap(object = object, genes.use = top20_pos$gene)


produces the following image which is not what I want:


I am aware that DoHeatmap function returns a ggplot2 object but after searching the internet for a long time, I have not been able to find  which geom layer I can add to achive my objective.

On the other hand, I have tried to generate a separate coloured annotation bar from another package called ComplexHeatmap with the intention of cropping it to fit the cluster demarcations on my heatmap generated with DoHeatmap but this has proven to be very time-consuming and inaccurrate:

library(ComplexHeatmap)

df = data.frame(type = c(rep("a", 18), rep("b", 3), rep("c", 2), rep("d", 1), rep("e", 1)))
ha = HeatmapAnnotation(df = df, col = list(type = c("a" =  "blue", "b" = "red", "c" = "green", "d" = "cyan", "e" = "magenta")))
draw(ha, 1:25)


which produces:


I will be very grateful for any hint on how to achieve my goal automatically and accurately.

Thank you in advance for your help.
I am not sure if it's a v3 or also v2 thing, but have you tried by setting group.by and label?

From ?Seurat::DoHeatmap:

group.by   A vector of variables to group cells by; pass 'ident' to group by cell identity classes
label      Label the cell identies above the color bar


If you prefer external tools, you can use pheatmap and setting annotation_col e annotation_colors.

First define a data.frame (df) containing the data you want in the bar (clusters in your case)

Description Condition
liver       Tumour
lung        Normal


Then you have to assign the colours

anno &lt;- as.data.frame(df)
anno_colori &lt;- list(
   Condition = c(Normal = '#FFC000', Tumour = '#0070C0'),
   Description = c(liver = '#D55E00', lung = '#66CC99')
)

pheatmap(mat,
     annotation_col = anno,
     annotation_colors = anno_colori,
)


The code above will add 2 bars on the top of your heatmap, one for Condition and another for Description.