Answers.Body: <p>You are almost there, if you set the <code>alpha</code> parameter within your <code>geom_violin()</code> call (to sth like 0.1) you should be able to get a plot similar to the example plot.</p>
  <p>The fact that you only have two data points for the <code>Stroma</code> group and these two points having similar values, you will end up getting a horizontal-line like violin for this group. Moreover, you do not have that many data points in general anyway so you might consider not using violins at all, especially if the outliers in <code>Tumour</code> group is coming from the same (maybe somewhat problematic?) sample, that might need to be dropped from the analysis. The reader should be able to grasp the essence of the data with our without violins (violins could help making the outliers obvious though).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-12T13:33:52.673Z
Answers.Text: Thanks @haci . In edited version of my post I am struggling with the same color scheme, please do you have any suggestion here?
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-12T13:47:06.500Z
Answers.Text: What you mean @M_
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-12T15:24:19.987Z
Answers.Text: @Exhausted Don't edit your question and branch off, ask a new question as a follow up (by mentioning this question) instead. When you edit questions that have been answered, you confuse future users by removing context. Scientific forums are not your personal help desk.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-13T11:36:25.180Z
Answers.Text: @Exhausted, you can try increasing the `alpha` parameter in your `geom_quasirandom()` call (or remove that parameter altogether).
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-11T17:03:26.477Z
Answers.LastActivityDate: 2022-07-11T17:03:26.477Z
Answers.UserDisplayName: haci
Body: <p>I want to have a plot violin plot around quasirandom dots - like below</p>
  <p><a href="https://i.sstatic.net/9EXRz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9EXRz.png" alt="enter image description here" /></a></p>
  <p>This is my data</p>
  <pre><code>&gt; str(long1)
  Classes ‘data.table’ and 'data.frame':  116 obs. of  4 variables:
   <span class="math-container">$ gene    : chr  "WT1" "KRT7" "MUC16" "EPCAM" ...
   $</span> variable: chr  &quot;1016&quot; &quot;1016&quot; &quot;1016&quot; &quot;1016&quot; ...
   <span class="math-container">$ value   : num  5.82 8.41 11.22 7.21 5.4 ...
   $</span> group   : chr  &quot;Tumour&quot; &quot;Tumour&quot; &quot;Tumour&quot; &quot;Tumour&quot; ...
   - attr(*, &quot;.internal.selfref&quot;)=&lt;externalptr&gt; 
  &gt;
  </code></pre>
  <p>By this code I get plot which does not have any violin</p>
  <pre><code>library(ggplot2)
  library(ggpubr)
  library(ggbeeswarm)
  p &lt;- ggplot(long1, aes(x=group, y=value,fill=group))
  p +geom_quasirandom(method = 'quasirandom',alpha = 0.2, width = 0.2,aes(colour = variable))+ labs(title=&quot;Supplementary Figure 6B&quot;, y = &quot;Expression(logcounts)&quot;)+theme_classic()+
    theme(legend.position=&quot;right&quot;) +
    theme(legend.title=element_blank())+facet_wrap(~gene, scales = &quot;free&quot;)+theme(strip.background = element_blank(),strip.text.x = element_text(size = 12,face=&quot;italic&quot;))
  </code></pre>
  <p><a href="https://i.sstatic.net/jzkyP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jzkyP.png" alt="enter image description here" /></a></p>
  <p>I also tried adding geom_violin like</p>
  <pre><code>p &lt;- ggplot(long1, aes(x=group, y=value,fill=group))
  p +geom_violin()+geom_quasirandom(method = 'quasirandom',alpha = 0.2, width = 0.2,aes(colour = variable))+ labs(title=&quot;Supplementary Figure 6B&quot;, y = &quot;Expression(logcounts)&quot;)+theme_classic()+
    theme(legend.position=&quot;right&quot;) +
    theme(legend.title=element_blank())+facet_wrap(~gene, scales = &quot;free&quot;)+theme(strip.background = element_blank(),strip.text.x = element_text(size = 12,face=&quot;italic&quot;))
  </code></pre>
  <p>But gives a weird plot not similar to what I want</p>
  <p><a href="https://i.sstatic.net/kVc4e.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kVc4e.png" alt="enter image description here" /></a></p>
  <p>Any help please</p>
  <p><em><strong>EDITED</strong></em></p>
  <p>Thanks to @haci</p>
  <p>By this code I get this plot but as you see the point color inside the violin is not really similar to what I want</p>
  <p>Any suggestion to get a similar color scheme for dots inside the violins</p>
  <pre><code>p &lt;- ggplot(long1, aes(x=group, y=value,fill=group))+guides(fill = &quot;none&quot;)
  p +geom_violin(alpha = 0.1)+scale_fill_manual(values=c(&quot;#fcf4e0&quot;, &quot;#fcf4e0&quot;))+geom_quasirandom(method = 'quasirandom',alpha = 0.2, width = 0.2,size=2,stroke=0.5,aes(colour = variable))+scale_color_hue(l = 5, c = 150)+ labs(title=&quot;Supplementary Figure 6B&quot;, y = &quot;Expression(logcounts)&quot;)+theme_classic()+
    theme(legend.position=&quot;right&quot;,legend.text=element_text(size=12)) +
    theme(legend.title=element_blank(),legend.text.align = 0,text = element_text(family = &quot;Arial&quot;),
          axis.title.x = element_text(size = 0.00001),
          axis.title.y = element_text(size = 17))+theme(axis.text = element_text(
            color=&quot;black&quot;, 
            size=12, 
            face=1)
          )+facet_wrap(~gene, scales = &quot;free&quot;)+theme(strip.background = element_blank(),strip.text.x = element_text(size = 17,face=&quot;italic&quot;))+ theme(axis.line = element_line(colour = 'black', size = 0.8))
  </code></pre>
  <p><a href="https://i.sstatic.net/siY8V.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/siY8V.png" alt="enter image description here" /></a></p>
  
Tags: <r><ggplot2>
Title: How to make a violin plot around quasirandom dots
ThreadText: # How to make a violin plot around quasirandom dots
  
  (Asked by: username_0 on 2022-07-11)
  
  I want to have a plot violin plot around quasirandom dots - like below
  
  [![enter image description here](https://i.sstatic.net/9EXRz.png)](https://i.sstatic.net/9EXRz.png)
  
  This is my data
  
  ```
  > str(long1)
  Classes ‘data.table’ and 'data.frame':  116 obs. of  4 variables:
   $ gene    : chr  "WT1" "KRT7" "MUC16" "EPCAM" ...
   $ variable: chr  "1016" "1016" "1016" "1016" ...
   $ value   : num  5.82 8.41 11.22 7.21 5.4 ...
   $ group   : chr  "Tumour" "Tumour" "Tumour" "Tumour" ...
   - attr(*, ".internal.selfref")=<externalptr> 
  >
  
  ```
  
  By this code I get plot which does not have any violin
  
  ```
  library(ggplot2)
  library(ggpubr)
  library(ggbeeswarm)
  p <- ggplot(long1, aes(x=group, y=value,fill=group))
  p +geom_quasirandom(method = 'quasirandom',alpha = 0.2, width = 0.2,aes(colour = variable))+ labs(title="Supplementary Figure 6B", y = "Expression(logcounts)")+theme_classic()+
    theme(legend.position="right") +
    theme(legend.title=element_blank())+facet_wrap(~gene, scales = "free")+theme(strip.background = element_blank(),strip.text.x = element_text(size = 12,face="italic"))
  
  ```
  
  [![enter image description here](https://i.sstatic.net/jzkyP.png)](https://i.sstatic.net/jzkyP.png)
  
  I also tried adding geom\_violin like
  
  ```
  p <- ggplot(long1, aes(x=group, y=value,fill=group))
  p +geom_violin()+geom_quasirandom(method = 'quasirandom',alpha = 0.2, width = 0.2,aes(colour = variable))+ labs(title="Supplementary Figure 6B", y = "Expression(logcounts)")+theme_classic()+
    theme(legend.position="right") +
    theme(legend.title=element_blank())+facet_wrap(~gene, scales = "free")+theme(strip.background = element_blank(),strip.text.x = element_text(size = 12,face="italic"))
  
  ```
  
  But gives a weird plot not similar to what I want
  
  [![enter image description here](https://i.sstatic.net/kVc4e.png)](https://i.sstatic.net/kVc4e.png)
  
  Any help please
  
  ***EDITED***
  
  Thanks to @username_1
  
  By this code I get this plot but as you see the point color inside the violin is not really similar to what I want
  
  Any suggestion to get a similar color scheme for dots inside the violins
  
  ```
  p <- ggplot(long1, aes(x=group, y=value,fill=group))+guides(fill = "none")
  p +geom_violin(alpha = 0.1)+scale_fill_manual(values=c("#fcf4e0", "#fcf4e0"))+geom_quasirandom(method = 'quasirandom',alpha = 0.2, width = 0.2,size=2,stroke=0.5,aes(colour = variable))+scale_color_hue(l = 5, c = 150)+ labs(title="Supplementary Figure 6B", y = "Expression(logcounts)")+theme_classic()+
    theme(legend.position="right",legend.text=element_text(size=12)) +
    theme(legend.title=element_blank(),legend.text.align = 0,text = element_text(family = "Arial"),
          axis.title.x = element_text(size = 0.00001),
          axis.title.y = element_text(size = 17))+theme(axis.text = element_text(
            color="black", 
            size=12, 
            face=1)
          )+facet_wrap(~gene, scales = "free")+theme(strip.background = element_blank(),strip.text.x = element_text(size = 17,face="italic"))+ theme(axis.line = element_line(colour = 'black', size = 0.8))
  
  ```
  
  [![enter image description here](https://i.sstatic.net/siY8V.png)](https://i.sstatic.net/siY8V.png)
  
  **Tags:** r, ggplot2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-07-11. Score: 3 | Accepted answer
  
  You are almost there, if you set the `alpha` parameter within your `geom_violin()` call (to sth like 0.1) you should be able to get a plot similar to the example plot.
  
  The fact that you only have two data points for the `Stroma` group and these two points having similar values, you will end up getting a horizontal-line like violin for this group. Moreover, you do not have that many data points in general anyway so you might consider not using violins at all, especially if the outliers in `Tumour` group is coming from the same (maybe somewhat problematic?) sample, that might need to be dropped from the analysis. The reader should be able to grasp the essence of the data with our without violins (violins could help making the outliers obvious though).
  
  > **Comments:**
  > **username_0**: Thanks @username_1 . In edited version of my post I am struggling with the same color scheme, please do you have any suggestion here?  
  > **username_0**: What you mean @M_  
  > **username_2**: @Exhausted Don't edit your question and branch off, ask a new question as a follow up (by mentioning this question) instead. When you edit questions that have been answered, you confuse future users by removing context. Scientific forums are not your personal help desk.  
  > **username_1**: @Exhausted, you can try increasing the `alpha` parameter in your `geom_quasirandom()` call (or remove that parameter altogether).  
  
  ---
  
  