<p>This happens because the violin plots are combined using <code>cowplot::plot_grid</code> before being returned by VlnPlot. You can prevent the plots from being combined by setting <code>combine=FALSE</code>, then modify each one by adding a boxplot, then combine the modified plots using <code>Seurat::CombinePlots</code>.</p>

<p>However, the combine argument is currently broken in VlnPlot. I have pushed a fix but it's not on the public branch yet. VlnPlot is just a wrapper around ExIPlot (expression by identity plot) in Seurat v3 so right now this will work:</p>

<pre><code>library(Seurat)
library(ggplot2)

plots &lt;- ExIPlot(object = pbmc_small,
                 features = c('PC1', 'PC2'),
                 pt.size = 1, 
                 combine = FALSE)

for(i in 1:length(plots)) {
  plots[[i]] &lt;- plots[[i]] + geom_boxplot() + theme(legend.position = 'none')
}
CombinePlots(plots)
</code></pre>

<p><a href="https://i.sstatic.net/NwrRy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NwrRy.png" alt="VlnPlot"></a></p>

<p>Note this answer is for Seurat v3</p>

CC BY-SA 4.0
2018-12-31T16:11:12.663Z
2018-12-31T16:11:12.663Z
TimStuart
<p>The <code>vioplot</code> package comes built in with boxplots. You can download it from CRAN or there are more features (including formula input and separate colours) in the development version on GitHub: <a href="https://github.com/TomKellyGenetics/vioplot" rel="nofollow noreferrer">https://github.com/TomKellyGenetics/vioplot</a></p>

<pre><code>devtools::install_github(“TomKellyGenetics/vioplot”)
library(“vioplot”)
vioplot(pbmc_small@dr@pca[,1]~pbmc_small@meta.data$ident)
</code></pre>

<p>To plot several PCs:</p>

<pre><code>library(“RColorBrewer”)
colours &lt;- brewer.pal(length(unique(pbmc_small@meta.data<span class="math-container">$ident)), “Set3”)
par(mfrow = c(1, 2))
vioplot(pbmc_small@dr@pca[,1]~pbmc_small@meta.data$</span>ident, main = “PC1”, xlab = “Identity”, col = colours)
vioplot(pbmc_small@dr@pca[,2]~pbmc_small@meta.data$ident , main = “PC2”, xlab = “Identity”, col = colours)
par(mfrow = c(1, 1))
</code></pre>

CC BY-SA 4.0
2018-12-29T03:59:38.967Z
You can add points to these with jitter: `plot(pbmc_small@dr@pca[,1]~jitter(pbmc_small@meta.data$ident, 0.5), add = TRUE)`
Tom Kelly ケリー・トム
CC BY-SA 4.0
2019-01-28T01:29:23.150Z
This version is now support on CRAN
Tom Kelly ケリー・トム
CC BY-SA 4.0
2018-12-29T03:54:48.347Z
2018-12-29T03:54:48.347Z
Tom Kelly ケリー・トム
<p>I am using the following function from seurat package to generate multiple violon plots and I am interested in adding box plots to them but it doesn't work when I have plotted different data at once.
Is there a way to solve it ?</p>

<p>For example, this works:</p>

<pre><code>library(Seurat)
VlnPlot(object = pbmc_small, features.plot = 'PC1') +
  geom_boxplot()
</code></pre>

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

<p>But this will simply lead into an empty box on top of my plots:</p>

<pre><code>VlnPlot(object = pbmc_small, features.plot = c('PC1', 'PC2')) +
  geom_boxplot()
</code></pre>

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

<r><scrnaseq><seurat><ggplot2>
Separate boxplots for multiple violin plot
# Separate boxplots for multiple violin plot

(Asked by: username_0 on 2018-12-28)

I am using the following function from seurat package to generate multiple violon plots and I am interested in adding box plots to them but it doesn't work when I have plotted different data at once.
Is there a way to solve it ?
For example, this works:
library(Seurat)
VlnPlot(object = pbmc_small, features.plot = 'PC1') +
  geom_boxplot()


But this will simply lead into an empty box on top of my plots:
VlnPlot(object = pbmc_small, features.plot = c('PC1', 'PC2')) +
  geom_boxplot()

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

---

## 2 answers

### Answer by username_1 on 2018-12-31. Score: 2 | Accepted answer

This happens because the violin plots are combined using cowplot::plot_grid before being returned by VlnPlot. You can prevent the plots from being combined by setting combine=FALSE, then modify each one by adding a boxplot, then combine the modified plots using Seurat::CombinePlots.
However, the combine argument is currently broken in VlnPlot. I have pushed a fix but it's not on the public branch yet. VlnPlot is just a wrapper around ExIPlot (expression by identity plot) in Seurat v3 so right now this will work:
library(Seurat)
library(ggplot2)

plots <- ExIPlot(object = pbmc_small,
                 features = c('PC1', 'PC2'),
                 pt.size = 1, 
                 combine = FALSE)

for(i in 1:length(plots)) {
  plots[[i]] <- plots[[i]] + geom_boxplot() + theme(legend.position = 'none')
}
CombinePlots(plots)


Note this answer is for Seurat v3


---

### Answer by username_2 on 2018-12-29. Score: 2

The vioplot package comes built in with boxplots. You can download it from CRAN or there are more features (including formula input and separate colours) in the development version on GitHub: https://github.com/TomKellyGenetics/vioplot
devtools::install_github(“TomKellyGenetics/vioplot”)
library(“vioplot”)
vioplot(pbmc_small@dr@pca[,1]~pbmc_small@meta.data$ident)

To plot several PCs:
library(“RColorBrewer”)
colours <- brewer.pal(length(unique(pbmc_small@meta.data$ident)), “Set3”)
par(mfrow = c(1, 2))
vioplot(pbmc_small@dr@pca[,1]~pbmc_small@meta.data$ident, main = “PC1”, xlab = “Identity”, col = colours)
vioplot(pbmc_small@dr@pca[,2]~pbmc_small@meta.data$ident , main = “PC2”, xlab = “Identity”, col = colours)
par(mfrow = c(1, 1))

> **Comments:**
> **username_2**: You can add points to these with jitter: `plot(pbmc_small@dr@pca[,1]~jitter(pbmc_small@meta.data$ident, 0.5), add = TRUE)`  
> **username_2**: This version is now support on CRAN  

---

