<p>To do so one workaround it to have your data in "long format" and then use the column that holds the "gene names" as the <code>x</code> variable while plotting.</p>

<p>You can use <code>FetchData()</code> to extract data from a <code>Seurat</code> object. <code>VlnPlot</code>'s default is the <code>data</code> slot (of the active assay if using Seurat v3 I suppose). And you can specify which cells and genes to retrieve.</p>

<pre><code>selected_cells &lt;- names(panc8<span class="math-container">$celltype[panc8$</span>celltype == "gamma"])
data &lt;- FetchData(panc8,
                    vars = c('FZD9','CTNNB1','APC'),
                    cells = selected_cells ,
                    slot = "data")
&gt; head(data)
           FZD9   CTNNB1      APC
D101_5        0 0.000000 0.000000
D101_43       0 2.007853 1.001958
D101_93       0 0.000000 0.000000
</code></pre>

<p><code>Melt()</code> would transform your data into "long format". By not specifying any arguments, we push for all of the info in the three variables to be gathered in two columns:</p>

<pre><code>long_data &lt;- melt(data)
No id variables; using all as measure variables
&gt; head(long_data)
  variable value
1     FZD9     0
2     FZD9     0
3     FZD9     0

&gt; tail(long_data)
     variable value
1870      APC     0
1871      APC     0
1872      APC     0
</code></pre>

<p><code>ggplot2</code> is used to add "violin" and "jitter" layers. You can customize the output to look (exactly) like the <code>VlnPlot()</code> output.</p>

<pre><code>ggplot(long_data,
       aes(x = variable, y = value)) +
  geom_violin() +
  geom_jitter(size = 0.1)
</code></pre>

<p><a href="https://i.sstatic.net/kDnuf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kDnuf.png" alt="enter image description here"></a></p>

<p>And here is the same graph generated by <code>VlnPlot()</code>:</p>

<p><a href="https://i.sstatic.net/3iZyv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3iZyv.png" alt="enter image description here"></a></p>

<p>There are no "violins" as the counts are almost entirely zeros. And see how different the ranges are in the y axes of the <code>VlnPlot</code>. So the "tweak" I have presented here would only work for genes that are expressed at similar levels / similar ranges. </p>

CC BY-SA 4.0
2019-11-18T10:16:12.723Z
thanks, this works well! The general approach will be useful moving forward with a number of other analyses as well. Thanks!
zdebruine
CC BY-SA 4.0
2019-11-17T10:22:25.797Z
2019-11-17T14:51:59.400Z
2019-11-17T14:51:59.400Z
haci
<p>Seurat VlnPlots are most commonly used to visualize differences in any given gene expression across multiple clusters or cell types. For example:</p>

<pre><code>VlnPlot(object = MouseCellAtlas, idents = c("T cell","Neutrophil","Erythroblast","Monocyte","Macrophage"), features = 'Fzd9')
</code></pre>

<p><a href="https://i.sstatic.net/ppD8p.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ppD8p.png" alt="Seurat VlnPlot for a single gene in multiple cluster idents"></a></p>

<p>But suppose I want to view the expression of several genes in just <code>idents = "T cell"</code>. I can do this to generate three separate plots:</p>

<pre><code>VlnPlot(object = mca, idents = 'T cell', features = c('Fzd9','Ctnnb1','Apc'), combine = TRUE, ncol = 3)
</code></pre>

<p><a href="https://i.sstatic.net/mMivT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mMivT.png" alt="Seurat plot for multiple genes in a single cluster ident"></a></p>

<p>But ideally I'd like this second plot to look just like the first plot, except with only a single tissue on the legend ("T cell") and multiple genes in the various colored violins. Unfortunately, I am not aware of any simple way to combine these violins into a single plot area.</p>

<p>This doesn't do what I need:</p>

<pre><code>VlnPlot(object = mca, idents = 'T cell', features = c('Fzd9','Ctnnb1','Apc'), combine = TRUE, ncol = 3)
</code></pre>

<p>Is there built-in functionality in Seurat for generating a VlnPlot for multiple genes in a single tissue in a single plot? Or can anyone suggest a workaround?</p>

<r><scrnaseq><seurat><ggplot2>
Seurat VlnPlot presenting expression of multiple genes in a single cluster
# Seurat VlnPlot presenting expression of multiple genes in a single cluster

(Asked by: username_0 on 2019-11-16)

Seurat VlnPlots are most commonly used to visualize differences in any given gene expression across multiple clusters or cell types. For example:
VlnPlot(object = MouseCellAtlas, idents = c("T cell","Neutrophil","Erythroblast","Monocyte","Macrophage"), features = 'Fzd9')


But suppose I want to view the expression of several genes in just idents = "T cell". I can do this to generate three separate plots:
VlnPlot(object = mca, idents = 'T cell', features = c('Fzd9','Ctnnb1','Apc'), combine = TRUE, ncol = 3)


But ideally I'd like this second plot to look just like the first plot, except with only a single tissue on the legend ("T cell") and multiple genes in the various colored violins. Unfortunately, I am not aware of any simple way to combine these violins into a single plot area.
This doesn't do what I need:
VlnPlot(object = mca, idents = 'T cell', features = c('Fzd9','Ctnnb1','Apc'), combine = TRUE, ncol = 3)

Is there built-in functionality in Seurat for generating a VlnPlot for multiple genes in a single tissue in a single plot? Or can anyone suggest a workaround?

**Tags:** r, scrnaseq, seurat, ggplot2

---

## 1 answers

### Answer by username_1 on 2019-11-17. Score: 2 | Accepted answer

To do so one workaround it to have your data in "long format" and then use the column that holds the "gene names" as the x variable while plotting.
You can use FetchData() to extract data from a Seurat object. VlnPlot's default is the data slot (of the active assay if using Seurat v3 I suppose). And you can specify which cells and genes to retrieve.
selected_cells <- names(panc8$celltype[panc8$celltype == "gamma"])
data <- FetchData(panc8,
                    vars = c('FZD9','CTNNB1','APC'),
                    cells = selected_cells ,
                    slot = "data")
> head(data)
           FZD9   CTNNB1      APC
D101_5        0 0.000000 0.000000
D101_43       0 2.007853 1.001958
D101_93       0 0.000000 0.000000

Melt() would transform your data into "long format". By not specifying any arguments, we push for all of the info in the three variables to be gathered in two columns:
long_data <- melt(data)
No id variables; using all as measure variables
> head(long_data)
  variable value
1     FZD9     0
2     FZD9     0
3     FZD9     0

> tail(long_data)
     variable value
1870      APC     0
1871      APC     0
1872      APC     0

ggplot2 is used to add "violin" and "jitter" layers. You can customize the output to look (exactly) like the VlnPlot() output.
ggplot(long_data,
       aes(x = variable, y = value)) +
  geom_violin() +
  geom_jitter(size = 0.1)


And here is the same graph generated by VlnPlot():

There are no "violins" as the counts are almost entirely zeros. And see how different the ranges are in the y axes of the VlnPlot. So the "tweak" I have presented here would only work for genes that are expressed at similar levels / similar ranges.

> **Comments:**
> **username_0**: thanks, this works well! The general approach will be useful moving forward with a number of other analyses as well. Thanks!  

---

