This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Moving labels in a volcano plot with ggplot2

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

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.

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

0 answers

No answers yet.

Log in to answer this question.