kevinblighe / EnhancedVolcano

Publication-ready volcano plots with enhanced colouring and labeling
399 stars 81 forks source link

controlling label repel within EnhancedVolcano #70

Closed davidbmorse closed 3 years ago

davidbmorse commented 3 years ago

Hi Kevin, thanks so much for this amazing resource!

Is it possible to control a label repelling variable or add x-axis limits to labels within Enhanced Volcano? For instance, could one make all labels of negative log2FC points be labeled on the left side of the plot and all labels of positive log2FC points be labeled on the right side of the plot?

Within a custom ggplot object, one could imaging doing something like this:

ggplot_object +
  geom_label_repel(data = table[ table$p_val < 0.05 & table$logFC < 0, ], 
                   aes(label = genelabels),
                   xlim = c(NA, -1),
                   seed = 1) +
  geom_label_repel(data = table[ table$p_val < 0.05 & table$logFC > 0, ], 
                   aes(label = genelabels),
                   xlim = c(1, NA), 
                   seed = 1)
kevinblighe commented 3 years ago

Hey davidbmorse, most of the repel functionality is [unfortunately] controlled by the default parameters of ggrepel's functions that are used by EnhancedVolcano, except for these parameters: https://github.com/kevinblighe/EnhancedVolcano/blob/master/R/EnhancedVolcano.R#L894-L908

So, we are somewhat at the mercy of how ggrepel lays out the labels. In most cases, I do not notice any specific pattern in how they are labeled, instead being somewhat random / arbitrary (?).

When labels extend beyond axes, I just extend the x-axis manually via xlim.

davidbmorse commented 3 years ago

Hi Kevin, thanks a lot for getting back to me and explaining this. Also, thanks for pointing me to the lines of your script that adjust some of the repel parameters.

kevinblighe commented 3 years ago

Hey david, sure, no problem. Yes, you can technically just copy the entire script and edit it on your side - this is just a single function package, after all.

It's not just those lines, per se, but anywhere where there's a geom_text_repel or geom_label_repel. Some of the code is admittedly redundant.