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

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

  • $\begingroup$ What are the warnings()? $\endgroup$
    – gringer
    Jul 8, 2022 at 6:51
  • 1
    $\begingroup$ 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 $\endgroup$
    – llrs
    Jul 8, 2022 at 9:50

1 Answer 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) +

@llrs 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.