EnhancedVolcano - Unable to customize the length of Connectors to Gene Labels
1
1
Entering edit mode
Peter ▴ 20
@fca336eb
Last seen 11 months ago
Portugal

Hello,

Thank you Kevin for this amazing EnhancedVolcano package! The overall result looks great. There's just one thing I am having difficulties fine-tuning, which is the length/dimension of the connectors of gene labels. I've searched around and I found a couple posts on this but the functions suggested are not working. Could you please help me understand what I might be doing wrong?

When I set the length of connectors (lengthConnectors = unit(1, 'npc')), the only thing that changes is the size of the arrowhead, not the connector line itself. This function is described to control "Length (size) of the connector arrowheads". Which is why if I turn off the arrowheads (arrowheads = FALSE), then this function doesn't have any effect. I was able to tune the width of the connector line through (widthConnectors = 1), but not the actual length of the connector lines.

Is there any way I can achieve this?

resddsCPM.df <- as.data.frame(resddsCPM)
keyvals <- ifelse(resddsCPM$padj > 0.05, 'grey30',
          ifelse(resddsCPM$log2FoldChange < -1, 'firebrick3',
            ifelse(resddsCPM$log2FoldChange > 1, 'royalblue', 'grey30')))
names(keyvals)[keyvals == 'royalblue'] <- 'Up'
names(keyvals)[keyvals == 'grey30'] <- 'Non-DEG'
names(keyvals)[keyvals == 'firebrick3'] <- 'Down'

#Highlight Genes of Interest
selected = c("IL1B", "FGF5", "IL1A")
#Plot Volcano
enhvolc <- EnhancedVolcano(resddsCPM.df, x = "log2FoldChange", y = "padj", lab = resddsCPM.df$geneID,
                pCutoff = 0.05, FCcutoff = 1,
                title = NULL,
                subtitle = NULL,
                caption = NULL,
                xlab = bquote(~Log[2]~"(Fold Change)"),
                ylab = bquote(~-Log[10] ~ "(" * italic(P[adj]) * ")"),
                drawConnectors = TRUE,
                pointSize = 1.2,
                colAlpha = 0.5,
                colCustom = keyvals,
                arrowheads = FALSE,
                lengthConnectors = unit(1, 'npc'),
                xlim = c(-11, 11),
                ylim = c(0, -log10(10e-306)),
                selectLab = selected
                )
enhvolc

Thank you for your help!

Peter

Transcriptomics EnhancedVolcano • 1.6k views
ADD COMMENT
1
Entering edit mode
Kevin Blighe ★ 3.9k
@kevin
Last seen 9 hours ago
Republic of Ireland

Hey Peter,

If arrowheads = TRUE, then the length and other parameters are used in code chunks like this in EnhancedVolcano:

  if (arrowheads) {
    arr <- arrow(length = lengthConnectors,
      type = typeConnectors, ends = endsConnectors)
  } else {
    arr <- NULL
  }

https://github.com/kevinblighe/EnhancedVolcano/blob/master/R/EnhancedVolcano.R#L808-L809

It's then used via ggrepel in a block like this:

  plot <- plot + geom_text_repel(
    data = subset(toptable,
      toptable[[y]] < pCutoff &
        abs(toptable[[x]]) > FCcutoff),
    aes(label = subset(toptable,
      toptable[[y]] < pCutoff &
        abs(toptable[[x]]) > FCcutoff)[["lab"]]),
    xlim = c(NA, NA),
    ylim = c(NA, NA),
    size = labSize,
    segment.color = colConnectors,
    segment.size = widthConnectors,
    arrow = arr,
    colour = labCol,
    fontface = labFace,
    parse = parseLabels,
    na.rm = TRUE,
    direction = directionConnectors,
    max.overlaps = max.overlaps,
    min.segment.length = min.segment.length)

https://github.com/kevinblighe/EnhancedVolcano/blob/master/R/EnhancedVolcano.R#L814-L833

As such, it's all some dictated by how ggrepel uses these parameters.


I don't believe there has ever been a parameter that allows you to control exactly the length of the connectors. However, one parameter that may help is to set a minimum length for each connector via:

' @param min.segment.length When drawConnectors = TRUE, specifies the minimum

' length of the connector line segments

This is somewhat elaborated here on ggrepel's documentation: https://ggrepel.slowkow.com/articles/examples.html

Kevin

ADD COMMENT
0
Entering edit mode

Thanks for your patience and help Kevin.

I've tried playing around with the min.segment.length, but unfortunately all it does is set a threshold for the length over which Connectors will be drawn. If the distance from a point and the gene label were 0.5cm and threshold is at 1cm, it simply doesnt draw the Connector. Instead, I was trying to find a way to enforce the Connector to extend until the desired length (say, 1 cm). From your feedback I realize there might not be an option within ggrepel to do this straightfoward.

Maybe if there was a way within EnhancedVolcano to define the distance at which gene labels appear from their corresponding points, then min.segment.length would work well. With this, I could force the gene labels to be shifted exactly 2 cm away from their corresponding datapoints, then call out min.segment.length to graph connectors with a 2 cm length.

Could you offer any advice if this would be feasible?

Thank you again for your help,

Pedro

ADD REPLY
1
Entering edit mode

Boa tarde, não sei cara. Me parece que não existe solução facil. Eu experimentei com tantas soluções potenciais desta página (https://ggrepel.slowkow.com/articles/examples.html) mas tudo me parecia variavle e não consistente. Apos, tirei a toalha e deixei a EnhancedVolcano como é.

ADD REPLY
1
Entering edit mode

Compreendo perfeitamente e agradeço toda a dedicação em servir a comunidade cientifica. Obrigado Kevin pela magnifica ferramenta!

ADD REPLY
0
Entering edit mode

Valeu cara!

ADD REPLY

Login before adding your answer.

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