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
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.
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.
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 gladlyI 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.
Follow this