text: user4595: I have single cell RNA-seq on 8 time points. I have clustered each time point to 2-3 clusters by seurat. I also have a list of differentially expressed genes between all my 1562 cells in 8 time points. I know how to plot this list of genes in heat map on each cluster of cells or a big heat map of my 1562 cells, but I have also sub-clusters for each cluster (time point). 
  Could you please help me to figure out how can I have a heat map with sub-clusters for each time point on which I am showing a list of differentially expressed genes? 
  Something like  the picture below where each day has been clustered to 2-3 sub-population then they plotted common differentially expressed genes between day points
  Edit
  Lets say 500 genes commonly are being differentially expressed in 8 time point. time point 1 has 3 sub-clusters of cells and time points 2 has 2 sub-clusters of cells. time point 3 and 4 both have 2 sub-clusters of cells. I want to heat map these 500 genes in cells in time point 1 (3 sub-clusters), time point 2 (2 sub-clusters), time point 23 (2 sub-clusters) and time point 4 (2 sub-clusters) in one unified heat map on which cells in each subclusteres (a,b and c) are in column and genes in rows but I don't have any idea how to do that. column annotation function in ComplexHeatmap likely works in this regard But I don't know how to define cells inside each  sub cluster in different colours 
  I can heat map of 500 genes only on time points easily by seurat but without underlying sub clusters
  > DoHeatmap(object = SubsetData(object = object, max.cells.per.ident =
  > 100), genes.use = 50 genes, slim.col.label = TRUE, group.label.rot =
  > TRUE)
  
  
  Figure 2 in this article.
  
  user3541: In case it is still helpful as the post is rather old, the code below would generate a heatmap with annotations thanks to the ComplexHeatmap package.
  But before that I would like to stress out the importance of example data, I bet a lot of experts could not help you just because of they did not have single cell data at their disposal.
  I am using some scRNA-seq data stored within a Seurat object. The expression data come from the @scale.data slot and the annotations are from the @meta.data slot. I am using a few general cell type markers as genes and 3 columns from the metadata slot (cell type, cell subtype, sample region). When using the ComplexHeatmap package, the trick is to have the same order in the annotation and actual data tables and this is how you should control what (in your case single cells) is plotted in what order.
  library(Seurat)
  library(dplyr)
  library(ComplexHeatmap)
  library(circlize) # for the colorRamp2() function
  
  seurat_object <- readRDS(...)
  
  # Annotations
  
  meta_data <- seurat_object@meta.data
  
  # order of annotations/colors are defined here
  ordered_meta_data <- meta_data[order(meta_data$cell_type), ]
  
  # OPTIONAL: YOU CAN PICK COLORS FOR EACH LEVEL OF ANNOTATION
  # HERE I PROVIDE COLORS FOR ONLY TWO OF THE THREE LEVELS, COLORS FOR THE
  # REMAINING LEVEL IS TAKEN CARE OF BY THE PACKAGE
  annotation_colors <- list("cell_type"= c("Epithelial" = "red",
                                           "Immune" = "orange",
                                           "Other" = "gray",
                                           "Stroma" = "green"),
                            "sample_region" = c("B" = "blue",
                                                "C" = "yellow",
                                                "N" = "maroon",
                                                "T" = "darkblue"))
  ha = HeatmapAnnotation(df = ordered_meta_data,
                         show_annotation_name = TRUE,
                         col = annotation_colors)
  
  # Expression data
  
  genes_to_use <- c("EPCAM",
                    "CD3D",
                    "NCR1",
                    "CD79A",
                    "LYZ",
                    "COL1A1",
                    "CLDN5",
                    "S100B",
                    "KIT")
  
  seurat_object <- ScaleData(seurat_object,
                             genes.use = genes_to_use)
  
  my_data <- seurat_object@scale.data
  
  # COLUMN ORDER OF THE EXPRESSION DATA SHOULD MATCH THE ROW ORDER OF THE
  # ANNOTATION TABLE
  my_data <- my_data[, rownames(ordered_meta_data)]
  
  # Heatmap
  
  col_fun = colorRamp2(c(-2, 0, 2), c("blue", "white", "red"))
  png(filename = "example_heatmap.png",
      width = 1000,
      height = 1000)
  Heatmap(
    my_data,
    col = col_fun,
    cluster_rows = FALSE,
    cluster_columns = FALSE,
    column_order = NULL,
    show_row_dend = FALSE,
    show_column_dend = FALSE,
    show_row_names = TRUE,
    show_column_names = FALSE,
    use_raster = TRUE,
    raster_device = c("png"),
    bottom_annotation = NULL,
    top_annotation = ha
  )
  dev.off()
  
  
  
original_text: 4595: <p>I have single cell RNA-seq on 8 time points. I have clustered each time point to 2-3 clusters by seurat. I also have a list of differentially expressed genes between all my 1562 cells in 8 time points. I know how to plot this list of genes in heat map on each cluster of cells or a big heat map of my 1562 cells, but I have also sub-clusters for each cluster (time point). </p>
  
  <p>Could you please help me to figure out how can I have a heat map with sub-clusters for each time point on which I am showing a list of differentially expressed genes? </p>
  
  <p>Something like  the picture below where each day has been clustered to 2-3 sub-population then they plotted common differentially expressed genes between day points</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Lets say 500 genes commonly are being differentially expressed in 8 time point. time point 1 has 3 sub-clusters of cells and time points 2 has 2 sub-clusters of cells. time point 3 and 4 both have 2 sub-clusters of cells. I want to heat map these 500 genes in cells in time point 1 (3 sub-clusters), time point 2 (2 sub-clusters), time point 23 (2 sub-clusters) and time point 4 (2 sub-clusters) in one unified heat map on which cells in each subclusteres (a,b and c) are in column and genes in rows but I don't have any idea how to do that. column annotation function in ComplexHeatmap likely works in this regard But I don't know how to define cells inside each  sub cluster in different colours </p>
  
  <p>I can heat map of 500 genes only on time points easily by seurat but without underlying sub clusters</p>
  
  <pre><code>&gt; DoHeatmap(object = SubsetData(object = object, max.cells.per.ident =
  &gt; 100), genes.use = 50 genes, slim.col.label = TRUE, group.label.rot =
  &gt; TRUE)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/71AtW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/71AtW.jpg" alt="enter image description here"></a></p>
  
  <p>Figure 2 in <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5668937/" rel="nofollow noreferrer">this article</a>.</p>
   3541: <p>In case it is still helpful as the post is rather old, the code below would generate a heatmap with annotations thanks to the <code>ComplexHeatmap</code> package.</p>
  
  <p>But before that I would like to stress out the importance of example data, I bet a lot of experts could not help you just because of they did not have single cell data at their disposal.</p>
  
  <p>I am using some scRNA-seq data stored within a <code>Seurat</code> object. The expression data come from the <code>@scale.data</code> slot and the annotations are from the <code>@meta.data</code> slot. I am using a few general cell type markers as genes and 3 columns from the metadata slot (cell type, cell subtype, sample region). When using the <code>ComplexHeatmap</code> package, the trick is to have the same order in the annotation and actual data tables and this is how you should control what (in your case single cells) is plotted in what order.</p>
  
  <pre><code>library(Seurat)
  library(dplyr)
  library(ComplexHeatmap)
  library(circlize) # for the colorRamp2() function
  
  seurat_object &lt;- readRDS(...)
  
  # Annotations
  
  meta_data &lt;- seurat_object@meta.data
  
  # order of annotations/colors are defined here
  ordered_meta_data &lt;- meta_data[order(meta_data$cell_type), ]
  
  # OPTIONAL: YOU CAN PICK COLORS FOR EACH LEVEL OF ANNOTATION
  # HERE I PROVIDE COLORS FOR ONLY TWO OF THE THREE LEVELS, COLORS FOR THE
  # REMAINING LEVEL IS TAKEN CARE OF BY THE PACKAGE
  annotation_colors &lt;- list("cell_type"= c("Epithelial" = "red",
                                           "Immune" = "orange",
                                           "Other" = "gray",
                                           "Stroma" = "green"),
                            "sample_region" = c("B" = "blue",
                                                "C" = "yellow",
                                                "N" = "maroon",
                                                "T" = "darkblue"))
  ha = HeatmapAnnotation(df = ordered_meta_data,
                         show_annotation_name = TRUE,
                         col = annotation_colors)
  
  # Expression data
  
  genes_to_use &lt;- c("EPCAM",
                    "CD3D",
                    "NCR1",
                    "CD79A",
                    "LYZ",
                    "COL1A1",
                    "CLDN5",
                    "S100B",
                    "KIT")
  
  seurat_object &lt;- ScaleData(seurat_object,
                             genes.use = genes_to_use)
  
  my_data &lt;- seurat_object@scale.data
  
  # COLUMN ORDER OF THE EXPRESSION DATA SHOULD MATCH THE ROW ORDER OF THE
  # ANNOTATION TABLE
  my_data &lt;- my_data[, rownames(ordered_meta_data)]
  
  # Heatmap
  
  col_fun = colorRamp2(c(-2, 0, 2), c("blue", "white", "red"))
  png(filename = "example_heatmap.png",
      width = 1000,
      height = 1000)
  Heatmap(
    my_data,
    col = col_fun,
    cluster_rows = FALSE,
    cluster_columns = FALSE,
    column_order = NULL,
    show_row_dend = FALSE,
    show_column_dend = FALSE,
    show_row_names = TRUE,
    show_column_names = FALSE,
    use_raster = TRUE,
    raster_device = c("png"),
    bottom_annotation = NULL,
    top_annotation = ha
  )
  dev.off()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qBjYH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qBjYH.png" alt="enter image description here"></a></p>
  