Answers.Body: <p>What happens if you group by gene?</p>
  <pre><code>&gt; long |&gt;
    ggplot() +
    aes(x=gene, y=value, colour=variable, group=gene) +
    geom_violin(width = 1.3) +
    geom_quasirandom(alpha = 0.2, width = 0.2) +
    theme_classic()
  </code></pre>
  <p>@llrs raised an insightful point in their comment. There's a good chance that the &quot;weird plot&quot; that you see is a side effect of trying to display individual &quot;grouped-by-variable&quot; boxplots that have too little data. Without knowing what you would like the boxplot to look like, it's hard to create something to improve the presentation.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-08T06:51:03.497Z
Answers.LastActivityDate: 2022-07-08T12:55:28.453Z
Answers.LastEditDate: 2022-07-08T12:55:28.453Z
Answers.UserDisplayName: gringer
Body: <p>I want to have a jitter violin coloured by sample ids but I get this weird plot</p>
  <pre><code>&gt; str(long)
  Classes ‘data.table’ and 'data.frame':  156 obs. of  3 variables:
   <span class="math-container">$ gene    : chr  "gene2" "gene3" "gene4" "gene1" ...
   $</span> variable: chr  &quot;1016&quot; &quot;1016&quot; &quot;1016&quot; &quot;1016&quot; ...
   $ value   : num  5.82 8.41 11.22 7.21 5.61 ...
   - attr(*, &quot;.internal.selfref&quot;)=&lt;externalptr&gt; 
  &gt;
  
  &gt; p &lt;- ggplot(long, aes(x=gene, y=value,colour=variable))
  &gt; p + geom_violin(width = 1.3) + geom_quasirandom(alpha = 0.2, width = 0.2)+ theme_classic()
  There were 21 warnings (use warnings() to see them)
  </code></pre>
  <p><a href="https://i.sstatic.net/cMycr.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cMycr.png" alt="enter image description here" /></a></p>
  <p>I can not figure out where I am doing something wrong that I get this instead of getting a proper violin plot by dots coloured with sample IDs</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-08T06:51:19.337Z
Comments.Text: What are the `warnings()`?
Comments.UserDisplayName: gringer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-08T09:50:04.743Z
Comments.Text: I see 17 different variables and 4 genes on the plot this are 153 values for 1 measurement for each sample and gene but your data.frame has only 156 rows. So at most you have 3 repeated measures for the same gene and variable. You can't make a (meaningful) boxplot of 1 value, so it is expected that very few boxplots can be drawn
Comments.UserDisplayName: llrs
Tags: <r><ggplot2>
Title: Jitter violin coloured by sample id
ThreadText: # Jitter violin coloured by sample id
  
  (Asked by: username_0 on 2022-07-07)
  
  I want to have a jitter violin coloured by sample ids but I get this weird plot
  
  ```
  > str(long)
  Classes ‘data.table’ and 'data.frame':  156 obs. of  3 variables:
   $ gene    : chr  "gene2" "gene3" "gene4" "gene1" ...
   $ variable: chr  "1016" "1016" "1016" "1016" ...
   $ value   : num  5.82 8.41 11.22 7.21 5.61 ...
   - attr(*, ".internal.selfref")=<externalptr> 
  >
  
  > p <- ggplot(long, aes(x=gene, y=value,colour=variable))
  > p + geom_violin(width = 1.3) + geom_quasirandom(alpha = 0.2, width = 0.2)+ theme_classic()
  There were 21 warnings (use warnings() to see them)
  
  ```
  
  [![enter image description here](https://i.sstatic.net/cMycr.png)](https://i.sstatic.net/cMycr.png)
  
  I can not figure out where I am doing something wrong that I get this instead of getting a proper violin plot by dots coloured with sample IDs
  
  **Tags:** r, ggplot2
  
  > **Comments:**
  > **username_1**: What are the `warnings()`?  
  > **username_2**: I see 17 different variables and 4 genes on the plot this are 153 values for 1 measurement for each sample and gene but your data.frame has only 156 rows. So at most you have 3 repeated measures for the same gene and variable. You can't make a (meaningful) boxplot of 1 value, so it is expected that very few boxplots can be drawn  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-07-08. Score: 1
  
  What happens if you group by gene?
  
  ```
  > long |>
    ggplot() +
    aes(x=gene, y=value, colour=variable, group=gene) +
    geom_violin(width = 1.3) +
    geom_quasirandom(alpha = 0.2, width = 0.2) +
    theme_classic()
  
  ```
  
  @username_2 raised an insightful point in their comment. There's a good chance that the "weird plot" that you see is a side effect of trying to display individual "grouped-by-variable" boxplots that have too little data. Without knowing what you would like the boxplot to look like, it's hard to create something to improve the presentation.
  
  
  ---
  
  