Adding p value above plot
2
0
Entering edit mode
9 weeks ago
a.stef.44 ▴ 10

Dear all, I am preparing violin plot showing differentially expressed genes between case/control using violin plot. I wanted show all genes in one graph and difference between case control.

Example Gene1 Case vs Control Gene2 Case vs Control Gene3 Case vs Control

For each comparison I have p value calculated using DESeq2 and I would like to include it above each comparison.

Example (the p values are only example) Gene1 Case vs Control + p value=0.02 above Gene2 Case vs Control + p value=0.03 above Gene3 Case vs Control + p value3=0.004 above

Code I used so far is works fine, with bold part I was able to include p value above graphs on the good position but they are all the same (I used p<0.05). I would like for each gene to include their specific p value :

ggplot (expr_long, aes(x = ID_REF, y = Value, fill = Response)) +
  geom_violin(position = position_dodge(0.9), alpha = 0.5) +
  geom_jitter(
    position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.9),
    size = 0.8, 
    alpha = 0.6 ) +  stat_summary(
    fun = mean,
    geom = "crossbar",
    width = 0.75, 
    fatten = 0.5, 
    color = "black",
    position = position_dodge(0.9) ) +
  scale_fill_manual(values = c("Case" = "#d73027", "Control" = "#4575b4")) +
  labs(  
    x = "Genes",
    y = "vst normalized counts",
    fill = "Response"  ) +
  theme_minimal()+  
  theme(    axis.title = element_text(size = 14)    ) **+
  geom_text(
    aes(
      x = ID_REF,
      y = max(Value) + 0.5, 
      label = "p < 0.05"   ),
    inherit.aes = FALSE,
    size = 4
  )**

Thank you in advance

p DESeq2 value violin boxplot • 644 views
ADD COMMENT
1
Entering edit mode

Honestly, just put it into ggtitle, or do it via inkscape. ggplot is great for many things, but adding custom text is always so terrible and tedious, and in the end looks poor. Publication-ready figures in my experience always need post-processing. By putting into ggtitle you have the information preserved in the plot and for the presentation can just crop it away.

ADD REPLY
0
Entering edit mode

Thank you very much, I used method proposed by marco.barr I it worked very nicely! In addition I would like to ask you as this is my first publication using R. What are you using for post-processing? I am always scared that I will decrease quality of plot.

ADD REPLY
0
Entering edit mode

Great! each journal will have settings for image quality. For my first few I used the png format and in R you can change the resolution. Try this: ggsave("plot.png", plot = p, width = 8, height = 6, dpi = 300) and change the parameters as you need. They are usually always good in png... but if ATpoint has other suggestions, you will accept them gladly

ADD REPLY
0
Entering edit mode

I use Inkscape, and usually save plots as pdf or tiff. If using pdf then quality will not decrease because it is vector-based. tiff must be saved as high resolution to not suffer from tiling effects. Don't use png or something with default settings, that will decrease quality. All I want to say is that you should not waste time on messing with little ggplot manipulations when you can do it in a minute with something like Inkscape because depending on final paper layout and figure guidelines, you anyway might need to do manual adjustments.

ADD REPLY
0
Entering edit mode
ADD REPLY
1
Entering edit mode
9 weeks ago
marco.barr ▴ 170

Show us the plots and data structure, maybe we could be more helpful. If I understand correctly, you have over each plot of genes the same value of p-value. If your expr_long data have the numerical value of the p-value you can try with label = paste0("p = ", p_value) in the part of your geom_text code

ADD COMMENT
0
Entering edit mode

You are genius!!! Thank you vary much!!!

ADD REPLY
1
Entering edit mode
9 weeks ago
SamGG ▴ 90

Did you have a look at ggsignif? There also other packages with the same goal.

https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html

ADD COMMENT

Login before adding your answer.

Traffic: 2145 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6