1
$\begingroup$

I want to have a plot violin plot around quasirandom dots - like below

enter image description here

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

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

Any help please

EDITED

Thanks to @haci

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

$\endgroup$

1 Answer 1

3
$\begingroup$

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).

$\endgroup$
4
  • $\begingroup$ Thanks @haci . In edited version of my post I am struggling with the same color scheme, please do you have any suggestion here? $\endgroup$
    – Angel
    Jul 12, 2022 at 13:33
  • $\begingroup$ What you mean @M_ $\endgroup$
    – Angel
    Jul 12, 2022 at 13:47
  • 2
    $\begingroup$ @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. $\endgroup$
    – Ram RS
    Jul 12, 2022 at 15:24
  • $\begingroup$ @Exhausted, you can try increasing the alpha parameter in your geom_quasirandom() call (or remove that parameter altogether). $\endgroup$
    – haci
    Jul 13, 2022 at 11:36

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.