<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>

CC BY-SA 4.0
2020-11-10T01:19:32.777Z
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.
Dahlia
CC BY-SA 4.0
2020-11-10T08:19:57.280Z
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()`.
haci
CC BY-SA 4.0
2020-11-11T00:36:56.230Z
What I mean is to compare the DEGs expressed between those two clusters. Does that make sense?
Dahlia
CC BY-SA 4.0
2020-11-11T00:38:01.063Z
```
> 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"
Dahlia
CC BY-SA 4.0
2020-11-11T09:00:52.240Z
`DoHeatmap()` takes a `Seurat` object as a first argument. Please go through the documentation and vignettes.
haci
CC BY-SA 4.0
2020-11-16T01:30:28.523Z
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!
Dahlia
CC BY-SA 4.0
2020-11-19T05:40:53.013Z
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")))
Dahlia
CC BY-SA 4.0
2020-11-09T12:23:43.847Z
2020-11-09T12:23:43.847Z
haci
<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>

CC BY-SA 4.0
2020-11-09T09:57:47.807Z
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.
user438383
CC BY-SA 4.0
2020-11-10T01:21:28.603Z
@user438383 Sorry for the ambiguity. I just attached the result of dput(cluster4_3.markers).
Dahlia
<seurat><heatmap>
Visualizing FindMarkers result in Seurat using Heatmap
# 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**: @user438383 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")))  

---

