<p>You want to (1) see the mean for each gene, and also to (2) calculate a ratio of expression levels of two genes, then compare it between clusters.</p>

<p>(1) First, notice that <code>vlnPlot()</code> is deprecated. Use <code>VlnPlot()</code>.</p>

<p>You can try using the parameter <code>do.sort=T</code>:</p>

<p><code>VlnPlot(object=seuset, features.plot=c("DDB_G0267412", "DDB_G0277853"), do.sort=T)</code></p>

<p>Alternatively, you can return the ggplot2 object and then plot the means etc:</p>

<pre><code>p &lt;- VlnPlot(object=seuset, features.plot="DDB_G0277853", do.return=T)
p &lt;- p + geom_boxplot(width=0.05)
p
</code></pre>

<hr>

<p>(2) There are a few problems with calculating the ratio of gene expression levels. Firstly, what do you mean by gene expression level and how do you measure it? Surely you can have the read counts, but how do you interpret them? Is 30 counts a high level? Is it much more than 60 counts, or is it roughly the same? The same applies to the calculated ratios and the differences between them, even if we ignore amplification, gene length and other biases. And it is very hard to interpret ratios if the reference can also change. The problem is somewhat similar to RT-qPCR, where people use a set of reference genes whose expression has previously been shown to be invariant under the conditions.</p>

<p>In theory, you could use the raw counts (object@raw.data), the log + normalized counts (object@data), or the scaled counts (object@scale.data). The raw counts are biased by sequencing-depth, and the ratio of log or scaled values are not easily interpretable or intuitive. Therefore the library-size normalized (non-log) values seem to be the best.</p>

<p>Additionally, you could calculate the ratio of two genes either (a) for each cell (paired), or (b) for each group.
(a) is problematic, because of the zero values: you will have many NaN and Inf values, which cannot be removed without biasing the data.</p>

<p>Here are some functions for retrieving and plotting data from the object:</p>

<pre><code>ident1 &lt;- WhichCells(seuset, ident=1)
ident2 &lt;- WhichCells(seuset, ident=2)

FetchData(seuset, vars.all='DDB_G0267412', cells.use=ident1, use.raw=T)

datatoplot1 &lt;- seuset@raw.data['DDB_G0267412', ident1] / seuset@raw.data['DDB_G0277853', ident1]
datatoplot2 &lt;- seuset@raw.data['DDB_G0267412', ident2] / seuset@raw.data['DDB_G0277853', ident2]

boxplot(datatoplot1, datatoplot2)

stripchart(datatoplot1, 
            vertical = TRUE, method = "jitter", 
            pch = 21, col = "dark green", 
            add = TRUE, at=1) 

stripchart(datatoplot2, 
            vertical = TRUE, method = "jitter", 
            pch = 21, col = "dark green", 
            add = TRUE, at=2) 
</code></pre>

CC BY-SA 4.0
2018-06-21T14:38:51.930Z
excuse me, with this command i have this picture in the link for my four clusters p <- VlnPlot(object=seuset, features.plot="DDB_G0277853", do.return=T)
p <- p + geom_boxplot(width=0.05)   https://drive.google.com/file/d/1r6eGQB225_jwtf7AWQo6Z2FKj4eVro42/view?usp=sharing, how i can have the plot for overall data side by side this plot?
Zizogolu
CC BY-SA 4.0
2018-06-21T14:39:07.143Z
i plotted that for all of cells but i don't know how to make a 5 violin together. https://drive.google.com/file/d/1MarsjXbTf0jg8e8e-1MTARNFQsOC9svw/view?usp=sharing   so i would be able to compare each cluster mean with the overall  mean, how i can have the plot for overall data side by side this plot? i plotted that for all of cells but i don't know how to make a 5 violin together
Zizogolu
CC BY-SA 4.0
2018-06-16T15:08:47.667Z
2018-06-16T15:08:47.667Z
Peter
<p>I have plotted the log normalized expression of two genes by violonplot for 4 clusters. I have links to my pictures and Seurat object too. My problem is this; in violin plot I can not see the mean or any centennial tendencies so that I don't know if two genes is expressing higher or lower in contrast to each other in each cluster.</p>

<p>violonplot vlnPlot(seuset,c(""))</p>

<p>Actually when I am thinking I see I need a violin or box plot showing  the  ratio of these genes to each other in each cluster and how nice to have mean also in the plot </p>

<p>Somebody knows how I can do that?</p>

CC BY-SA 4.0
2018-06-15T15:26:52.070Z
Please, remember to add the code you use to make it easier to provide the accurate advise to help you. But do you want to see the mean of the cluster or to see the differences of genes between clusters?
llrs
<r><single-cell><seurat>
Violinplot of gene expression
# Violinplot of gene expression

(Asked by: username_0 on 2018-06-15)

I have plotted the log normalized expression of two genes by violonplot for 4 clusters. I have links to my pictures and Seurat object too. My problem is this; in violin plot I can not see the mean or any centennial tendencies so that I don't know if two genes is expressing higher or lower in contrast to each other in each cluster.

violonplot vlnPlot(seuset,c(""))

Actually when I am thinking I see I need a violin or box plot showing the ratio of these genes to each other in each cluster and how nice to have mean also in the plot

Somebody knows how I can do that?

**Tags:** r, single-cell, seurat
> **Comments:**
> **username_1**: Please, remember to add the code you use to make it easier to provide the accurate advise to help you. But do you want to see the mean of the cluster or to see the differences of genes between clusters?  

---

## 1 answers

### Answer by username_2 on 2018-06-16. Score: 4 | Accepted answer

You want to (1) see the mean for each gene, and also to (2) calculate a ratio of expression levels of two genes, then compare it between clusters.
(1) First, notice that vlnPlot() is deprecated. Use VlnPlot().
You can try using the parameter do.sort=T:
VlnPlot(object=seuset, features.plot=c("DDB_G0267412", "DDB_G0277853"), do.sort=T)
Alternatively, you can return the ggplot2 object and then plot the means etc:
p <- VlnPlot(object=seuset, features.plot="DDB_G0277853", do.return=T)
p <- p + geom_boxplot(width=0.05)
p


(2) There are a few problems with calculating the ratio of gene expression levels. Firstly, what do you mean by gene expression level and how do you measure it? Surely you can have the read counts, but how do you interpret them? Is 30 counts a high level? Is it much more than 60 counts, or is it roughly the same? The same applies to the calculated ratios and the differences between them, even if we ignore amplification, gene length and other biases. And it is very hard to interpret ratios if the reference can also change. The problem is somewhat similar to RT-qPCR, where people use a set of reference genes whose expression has previously been shown to be invariant under the conditions.
In theory, you could use the raw counts (object@raw.data), the log + normalized counts (object@data), or the scaled counts (object@scale.data). The raw counts are biased by sequencing-depth, and the ratio of log or scaled values are not easily interpretable or intuitive. Therefore the library-size normalized (non-log) values seem to be the best.
Additionally, you could calculate the ratio of two genes either (a) for each cell (paired), or (b) for each group.
(a) is problematic, because of the zero values: you will have many NaN and Inf values, which cannot be removed without biasing the data.
Here are some functions for retrieving and plotting data from the object:
ident1 <- WhichCells(seuset, ident=1)
ident2 <- WhichCells(seuset, ident=2)

FetchData(seuset, vars.all='DDB_G0267412', cells.use=ident1, use.raw=T)

datatoplot1 <- seuset@raw.data['DDB_G0267412', ident1] / seuset@raw.data['DDB_G0277853', ident1]
datatoplot2 <- seuset@raw.data['DDB_G0267412', ident2] / seuset@raw.data['DDB_G0277853', ident2]

boxplot(datatoplot1, datatoplot2)

stripchart(datatoplot1, 
            vertical = TRUE, method = "jitter", 
            pch = 21, col = "dark green", 
            add = TRUE, at=1) 

stripchart(datatoplot2, 
            vertical = TRUE, method = "jitter", 
            pch = 21, col = "dark green", 
            add = TRUE, at=2)

> **Comments:**
> **username_0**: excuse me, with this command i have this picture in the link for my four clusters p <- VlnPlot(object=seuset, features.plot="DDB_G0277853", do.return=T) p <- p + geom_boxplot(width=0.05)   https://drive.google.com/file/d/1r6eGQB225_jwtf7AWQo6Z2FKj4eVro42/view?usp=sharing, how i can have the plot for overall data side by side this plot?  
> **username_0**: i plotted that for all of cells but i don't know how to make a 5 violin together. https://drive.google.com/file/d/1MarsjXbTf0jg8e8e-1MTARNFQsOC9svw/view?usp=sharing   so i would be able to compare each cluster mean with the overall  mean, how i can have the plot for overall data side by side this plot? i plotted that for all of cells but i don't know how to make a 5 violin together  

---

