Answers.Body: <p>You need to order the marker matrix (e.g. by <code>avg_logFC</code>) before calling <code>DoHeatMap</code>.</p>
  
  <pre><code>library(dplyr)
  all.markers &lt;- FindAllMarkers(object = obj)
  top20 &lt;- all.markers %&gt;% group_by(cluster) %&gt;% top_n(20, avg_logFC)
  DoHeatmap(object = obj, genes.use = top20$gene, slim.col.label = TRUE, remove.key = TRUE)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-17T12:23:40.313Z
Answers.LastActivityDate: 2019-07-17T12:28:48.373Z
Answers.LastEditDate: 2019-07-17T12:28:48.373Z
Answers.UserDisplayName: fra
Body: <p>I have a list of genes that I'd like to visualize using the DoHeatmap function in Seurat. However, the output of the heatmap does not result in hierarchical clustering and therefore makes it very difficult to interpret. My code is,</p>
  
  <pre><code> DoHeatmap(object = obj, genes.use = genes), 
            slim.col.label = TRUE, remove.key = T,group.label.rot = F, use.scaled = T)
  </code></pre>
  
  <p><a href="https://i.sstatic.net/x85hy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/x85hy.png" alt="Seurat"></a> </p>
  
  <p>Is there a way to adjust the <code>DoHeatmap</code> command to rank the cells by the intensity of gene expression? Here's an example output:</p>
  
  <p><a href="https://i.sstatic.net/Jy8Xs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Jy8Xs.png" alt="enter image description here"></a></p>
  
Tags: <r><seurat><heatmap>
Title: DoHeatmap Hierarchical Clustering Seurat
ThreadText: # DoHeatmap Hierarchical Clustering Seurat
  
  (Asked by: username_0 on 2019-07-12)
  
  I have a list of genes that I'd like to visualize using the DoHeatmap function in Seurat. However, the output of the heatmap does not result in hierarchical clustering and therefore makes it very difficult to interpret. My code is,
  
  ```
   DoHeatmap(object = obj, genes.use = genes), 
            slim.col.label = TRUE, remove.key = T,group.label.rot = F, use.scaled = T)
  
  ```
  
  [![Seurat](https://i.sstatic.net/x85hy.png)](https://i.sstatic.net/x85hy.png)
  
  Is there a way to adjust the `DoHeatmap` command to rank the cells by the intensity of gene expression? Here's an example output:
  
  [![enter image description here](https://i.sstatic.net/Jy8Xs.png)](https://i.sstatic.net/Jy8Xs.png)
  
  **Tags:** r, seurat, heatmap
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-07-17. Score: 1
  
  You need to order the marker matrix (e.g. by `avg_logFC`) before calling `DoHeatMap`.
  
  ```
  library(dplyr)
  all.markers <- FindAllMarkers(object = obj)
  top20 <- all.markers %>% group_by(cluster) %>% top_n(20, avg_logFC)
  DoHeatmap(object = obj, genes.use = top20$gene, slim.col.label = TRUE, remove.key = TRUE)
  
  ```
  
  
  ---
  
  