Answers.Body: <p>In your <code>DoHeatmap()</code> call, you do not provide features so the function does not know which genes/features to use for the heatmap.</p>
  <p>In your last function call, you are trying to group based on a continuous variable <code>pct.1</code> whereas <code>group_by</code> expects a categorical variable.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-10T01:19:32.777Z
Answers.Text: I understand a little bit more now. I just want to show the DEGs expressed in both clusters in 1 heatmap. But I failed (still failing) to write the command logically.
Answers.UserDisplayName: Dahlia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-10T08:19:57.280Z
Answers.Text: I am having a hard time understanding "DEGs expressed in both clusters", by definition a DEG is expressed in one of the clusters, not both. You can feed `rownames(cluster4_3.markers)` to the `features` variable of `DoHeatmap()`.
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T00:36:56.230Z
Answers.Text: What I mean is to compare the DEGs expressed between those two clusters. Does that make sense?
Answers.UserDisplayName: Dahlia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T00:38:01.063Z
Answers.Text: ```
  > DoHeatmap(cluster4_3.markers, features = rownames(cluster4_3.markers)) + 
  +   scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))
  Error in UseMethod(generic = "DefaultAssay", object = object) : 
    no applicable method for 'DefaultAssay' applied to an object of class "data.frame"
Answers.UserDisplayName: Dahlia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T09:00:52.240Z
Answers.Text: `DoHeatmap()` takes a `Seurat` object as a first argument. Please go through the documentation and vignettes.
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-16T01:30:28.523Z
Answers.Text: Thank you for bearing with me.
  I edited the command using the only seurat object I've created with the main set of data:
  ``` 
  > DoHeatmap(tg14, features = rownames(cluster4_3.markers)) + 
  +   scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))
  Error: cannot allocate vector of size 580.8 Mb
  ```
  I am currently looking through the vignettes but if you can still give me more clues, that'll be great!
Answers.UserDisplayName: Dahlia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-19T05:40:53.013Z
Answers.Text: Thanks a lot for helping. This fixed my problem: 
  ```
  top10 <- cluster4_3.markers %>% top_n(n = 10, wt = avg_logFC)
  DoHeatmap(tg14, features = top10$gene) + NoLegend() + 
    scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))
Answers.UserDisplayName: Dahlia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-09T12:23:43.847Z
Answers.LastActivityDate: 2020-11-09T12:23:43.847Z
Answers.UserDisplayName: haci
Body: <p>I used FindMarkers to find the DEGs between two clusters in my dataset using Seurat. I am trying to visualize the outcome using a heatmap but I failed to write the command in R.</p>
  <pre><code>dput(cluster4_3.markers)
                p_val  avg_logFC pct.1 pct.2    p_val_adj
  Vim    1.803527e-44 -1.1689785 0.996 0.999 3.458985e-40
  Lgals7 1.479278e-38  1.7615232 0.993 0.552 2.837108e-34
  Anxa2  1.797016e-37 -1.3971764 0.629 0.991 3.446497e-33
  Tmsb10 6.936830e-31  0.7937881 1.000 1.000 1.330415e-26
  Ptma   7.518439e-27  0.5622808 1.000 1.000 1.441961e-22
  Jund   2.044576e-25 -0.9881766 0.993 0.999 3.921293e-21
  </code></pre>
  <p>When I tried:</p>
  <pre><code>DoHeatmap(cluster4_3.markers, features = NULL) + 
  scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = &quot;RdYlBu&quot;)))
  Error in UseMethod(generic = &quot;DefaultAssay&quot;, object = object) : 
    no applicable method for 'DefaultAssay' applied to an object of class &quot;data.frame&quot;
  </code></pre>
  <p>It didn't work. I was trying to replicate this command:</p>
  <pre><code>top10 &lt;- pbmc.markers %&gt;% group_by(cluster) %&gt;% top_n(n = 10, wt = avg_logFC)
  DoHeatmap(pbmc, features = top10$gene) + NoLegend() + 
    scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = &quot;RdYlBu&quot;)))
  </code></pre>
  <p>I tried to extract some info from the csv file but I couldn't determine which parameter is important (p_val avg_logFC   pct.1   pct.2   p_val_adj). Also, I didn't know which parameter to use to use the group_by function. That's one of my attempts:</p>
  <pre><code>clus4vs3 &lt;- cluster4_3.markers$p_val %&gt;% 
      group_by(pct.1) %&gt;% 
      top_n(n = 10, wt = avg_logFC)
  Error in UseMethod(&quot;group_by_&quot;) :
    no applicable method for 'group_by_' applied to an object of class &quot;c('double', 'numeric')&quot;
  </code></pre>
  <p>Now that I understand 'group_by' only accepts a categorical variable, how can I write a command that displays the top20 differentially expressed genes between cluster 4 and 3 in a heatmap ?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-09T09:57:47.807Z
Comments.Text: Please a) include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data, (i.e. by using ``dput(cluster4_3.markers)`` b) tell us what didn't work because it's not 'obvious' to us since we can't see your data. Include details of all error messages. We can't help you otherwise.
Comments.UserDisplayName: user438383
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-10T01:21:28.603Z
Comments.Text: @user438383 Sorry for the ambiguity. I just attached the result of dput(cluster4_3.markers).
Comments.UserDisplayName: Dahlia
Tags: <seurat><heatmap>
Title: Visualizing FindMarkers result in Seurat using Heatmap
ThreadText: # Visualizing FindMarkers result in Seurat using Heatmap
  
  (Asked by: username_0 on 2020-11-09)
  
  I used FindMarkers to find the DEGs between two clusters in my dataset using Seurat. I am trying to visualize the outcome using a heatmap but I failed to write the command in R.
  
  ```
  dput(cluster4_3.markers)
                p_val  avg_logFC pct.1 pct.2    p_val_adj
  Vim    1.803527e-44 -1.1689785 0.996 0.999 3.458985e-40
  Lgals7 1.479278e-38  1.7615232 0.993 0.552 2.837108e-34
  Anxa2  1.797016e-37 -1.3971764 0.629 0.991 3.446497e-33
  Tmsb10 6.936830e-31  0.7937881 1.000 1.000 1.330415e-26
  Ptma   7.518439e-27  0.5622808 1.000 1.000 1.441961e-22
  Jund   2.044576e-25 -0.9881766 0.993 0.999 3.921293e-21
  
  ```
  
  When I tried:
  
  ```
  DoHeatmap(cluster4_3.markers, features = NULL) + 
  scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))
  Error in UseMethod(generic = "DefaultAssay", object = object) : 
    no applicable method for 'DefaultAssay' applied to an object of class "data.frame"
  
  ```
  
  It didn't work. I was trying to replicate this command:
  
  ```
  top10 <- pbmc.markers %>% group_by(cluster) %>% top_n(n = 10, wt = avg_logFC)
  DoHeatmap(pbmc, features = top10$gene) + NoLegend() + 
    scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))
  
  ```
  
  I tried to extract some info from the csv file but I couldn't determine which parameter is important (p\_val avg\_logFC pct.1 pct.2 p\_val\_adj). Also, I didn't know which parameter to use to use the group\_by function. That's one of my attempts:
  
  ```
  clus4vs3 <- cluster4_3.markers$p_val %>% 
      group_by(pct.1) %>% 
      top_n(n = 10, wt = avg_logFC)
  Error in UseMethod("group_by_") :
    no applicable method for 'group_by_' applied to an object of class "c('double', 'numeric')"
  
  ```
  
  Now that I understand 'group\_by' only accepts a categorical variable, how can I write a command that displays the top20 differentially expressed genes between cluster 4 and 3 in a heatmap ?
  
  **Tags:** seurat, heatmap
  
  > **Comments:**
  > **username_1**: Please a) include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data, (i.e. by using ``dput(cluster4_3.markers)`` b) tell us what didn't work because it's not 'obvious' to us since we can't see your data. Include details of all error messages. We can't help you otherwise.  
  > **username_0**: @username_1 Sorry for the ambiguity. I just attached the result of dput(cluster4_3.markers).  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-11-09. Score: 1 | Accepted answer
  
  In your `DoHeatmap()` call, you do not provide features so the function does not know which genes/features to use for the heatmap.
  
  In your last function call, you are trying to group based on a continuous variable `pct.1` whereas `group_by` expects a categorical variable.
  
  > **Comments:**
  > **username_0**: I understand a little bit more now. I just want to show the DEGs expressed in both clusters in 1 heatmap. But I failed (still failing) to write the command logically.  
  > **username_2**: I am having a hard time understanding "DEGs expressed in both clusters", by definition a DEG is expressed in one of the clusters, not both. You can feed `rownames(cluster4_3.markers)` to the `features` variable of `DoHeatmap()`.  
  > **username_0**: What I mean is to compare the DEGs expressed between those two clusters. Does that make sense?  
  > **username_0**: ``` > DoHeatmap(cluster4_3.markers, features = rownames(cluster4_3.markers)) +  +   scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu"))) Error in UseMethod(generic = "DefaultAssay", object = object) :    no applicable method for 'DefaultAssay' applied to an object of class "data.frame"  
  > **username_2**: `DoHeatmap()` takes a `Seurat` object as a first argument. Please go through the documentation and vignettes.  
  > **username_0**: Thank you for bearing with me. I edited the command using the only seurat object I've created with the main set of data: ```  > DoHeatmap(tg14, features = rownames(cluster4_3.markers)) +  +   scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu"))) Error: cannot allocate vector of size 580.8 Mb ``` I am currently looking through the vignettes but if you can still give me more clues, that'll be great!  
  > **username_0**: Thanks a lot for helping. This fixed my problem:  ``` top10 <- cluster4_3.markers %>% top_n(n = 10, wt = avg_logFC) DoHeatmap(tg14, features = top10$gene) + NoLegend() +    scale_fill_gradientn(colors = rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))  
  
  ---
  
  