Moving labels in a volcano plot with ggplot2
0
1
Entering edit mode
6 months ago

Hi all,

I am relatively new to ggplot2 and I am currently using it to generate volcano plots from RNA-seq data. However, I am struggling to manipulate the location of labels for specific data points.

For example, the label IL4I1 is mostly obscured by other data points and would likely look better if it could be moved to the right.

Furthermore, I have only opted to plot genes with a log10 padj of > 2 because I wouldn't be able to prevent the plot from becoming too cluttered. However, it would be great if I could include them. I have been looking at gg_repel vignette but have been struggling to get it working.

Have you got any suggestion for label manipulation?

Please find my code below:

theme_set(theme_classic(base_size = 10) +
        theme(
          axis.title.y = element_text(face = "bold", margin = margin(0,20,0,0), size = rel(1.1), color = 'black'),
          axis.title.x = element_text(hjust = 0.5, face = "bold", margin = margin(20,0,0,0), size = rel(1.1), color = 'black'),
          plot.title = element_text(hjust = 0.5)
        ))

ggplot(data = res_table_condition_ts, aes(x = log2FoldChange, y = -log10(padj), col = diffexpressed, label = delabel)) +
  geom_vline(xintercept = c(-1, 1), col = "gray", linetype = 'dashed') +
  geom_hline(yintercept = -log10(0.05), col = "gray", linetype = 'dashed') +
  geom_point() +
  scale_color_manual(values = c("#00AFBB", "grey", "#bb0c00"),    
                     labels = c("Downregulated", "Not significant", "Upregulated")) +
  labs(color = 'Case vs Control', #legend_title, 
       x = expression("log"[2]*"FC"), y = expression("-log"[10]*"p-value")) +
  scale_x_continuous(breaks = seq(-10, 10, 2)) 
  ggtitle("Case vs Control") +
  geom_text_repel(max.overlaps = 20)

Volcano plot

ggplot2 volcano-plot • 849 views
ADD COMMENT
0
Entering edit mode

You can for example use min.segment.length=0to force it to always draw a connector line between point and label. Using geom_label_repel instead of geom_text_repel additionally puts a text box around the label that can help as well. Go through ?geom_text_repel, depending on usecase the nudge_* options might be relevant. With many labels it often comes down to manually altering things to finally achieve the figure for the presentation or paper.

ADD REPLY
0
Entering edit mode

If you have Adobe Illustrator, I think that would be the easiest way to move labels around.

ADD REPLY

Login before adding your answer.

Traffic: 1992 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