Enhanced volcano: how to italicize or change the font of legend?
1
0
Entering edit mode
4.2 years ago
chiongchih96 ▴ 10

I'm trying to italicize the legend of figure made by enhanced volcano (not label). Is there any way to do that? I read the package tutorial but it was not attentioned.

R enhancedvolcano • 5.1k views
ADD COMMENT
0
Entering edit mode

Hi Kevin

I have been able to plot the data as a volcano plot. However, I have some data points which share the exact same adjusted p value and a similar FC. And so the labels are probably getting overlapped and one label is obscuring the one closest to it. Please let me know if I can change the coordinates of the annotations/labels or is there a way to spread them out so all the labels are visible.

Cheers Farheen

ADD REPLY
3
Entering edit mode
4.2 years ago

Hello, thank you for the important question. Getting these simple things correct can make a figure look a lot better.

You can italicize the legend labels via the use of the expression() and / or bquote() functions, as I show below:

library(EnhancedVolcano)
library(airway)
library(magrittr)

data('airway')
airway$dex %<>% relevel('untrt')
library('DESeq2')

dds <- DESeqDataSet(airway, design = ~ cell + dex)
dds <- DESeq(dds, betaPrior=FALSE)
res2 <- results(dds,
  contrast = c('cell', 'N061011', 'N61311'))
res2 <- lfcShrink(dds,
  contrast = c('cell', 'N061011', 'N61311'), res=res2, type = 'normal')


EnhancedVolcano(res2,
  lab = rownames(res2),
  x = 'log2FoldChange',
  y = 'pvalue',
  xlim = c(-6,6),
  xlab = bquote(~Log[2]~ 'fold change'),
  pCutoff = 10e-14,
  FCcutoff = 2.0,
  pointSize = 3.0,
  labSize = 3.0,
  colAlpha = 0.75,
  legendLabels = c('NS', expression(Log[2] ~ FC), expression(italic(p - value)), 
      expression(italic(p - value ~ and ~ log[2] ~ FC))),
  legendPosition = 'right',
  legendLabSize = 16,
  legendIconSize = 4.0,
  drawConnectors = TRUE,
  widthConnectors = 0.2,
  colConnectors = 'grey30')

77

Also, if you note the default value of ylab, you'll see a more complex example of how to do this to only a single character:

ylab = bquote(~-Log[10] ~ italic(P))

Note the italicized 'P' in the default y-axis label.

Kevin

ADD COMMENT
0
Entering edit mode

Thanks for the answer! It works well in this case. But my situation is a little different and this solution doesn't work. Labels have been created as key-value pairs by ifelse statements before legendLabels().

keyvals.color <- ifelse(
  rownames(res) %in% Acinetobacter, 'gold',
  ifelse(rownames(res) %in% Burkholderia, 'red',
         ifelse(rownames(res) %in% Escherichia,'green',
                ifelse(rownames(res) %in% Pseudomonas, 'blue',
                       ifelse(rownames(res) %in% Yersinia, 'pink','black'
         )))))
names(keyvals.color)[keyvals.color == 'gold'] <- 'Acinetobacter'
names(keyvals.color)[keyvals.color == 'red'] <- 'Burkholderia'
names(keyvals.color)[keyvals.color == 'green'] <- 'Escherichia'
names(keyvals.color)[keyvals.color == 'blue'] <- 'Pseudomonas'
names(keyvals.color)[keyvals.color == 'pink'] <- 'Yersinia' 
names(keyvals.color)[keyvals.color == 'black'] <- 'unpassed'
EnhancedVolcano(res_after1,
                      ylab=bquote(~-Log[10]~italic(P[adjusted])),
                      lab = rownames(res_after1),
                      title='A-ARGs',
                      drawConnectors=TRUE,
                      legendPosition='right',
                      legendLabels = c(expression(italic(Acinetobacter)),expression(italic(Burkholderia)),expression(italic(Escherichia)),expression(italic(Pseudomonas)),expression(italic(Yersinia)),expression(italic(unpassed))),
                      #.legend = c('Acinetobacter','Burkholderia','Escherichia','Pseudomonas','Yersinia','unpassed'),
                      subtitle=NULL,
                      caption = NULL,
                      colCustom = keyvals.color,
                      colAlpha=1,
                      legendLabSize=8,
                      x = 'log2FoldChange', FCcutoff=1.5, axisLabSize = 15,
                      y = 'padj', ylim=c(0, -log10(10e-10)), pCutoff=0.05, 
                      pointSize=3.0,
                      labSize=3.0,
                      xlim = c(-7, 7))

I ran the code the labels were not italicized. So in this case, legendLabels() is not working. Is there a way to italicize the label in this case?

ADD REPLY
1
Entering edit mode

Hey again, oh, I see what you mean. One can appreciate how difficult it can be to get just the right plot. Fortunately, due to the way that I designed this package, any user can effectively modify any part of the plot after the original plot has been created via the standard ggplot2 functions.

Taking another example from the vignette, I think that following this will give you what you need: basically, I 'add on' another function to EnhancedVolcano(), called scale_colour_manual().

At this point, it seems overly complex, but it's difficult to code for every possible eventuality.

Hope that it helps!

library(EnhancedVolcano)
library(airway)
library(magrittr)

data('airway')
airway$dex %<>% relevel('untrt')
library('DESeq2')

dds <- DESeqDataSet(airway, design = ~ cell + dex)
dds <- DESeq(dds, betaPrior=FALSE)
res2 <- results(dds,
  contrast = c('cell', 'N061011', 'N61311'))
res2 <- lfcShrink(dds,
  contrast = c('cell', 'N061011', 'N61311'), res=res2, type = 'normal')

###
###

# create custom key-value pairs for 'high', 'low', 'mid' expression by fold-change
  # this can be achieved with nested ifelse statements
  keyvals <- ifelse(
    res2$log2FoldChange < -2.5, 'royalblue',
      ifelse(res2$log2FoldChange > 2.5, 'gold',
        'black'))

  names(keyvals)[keyvals == 'gold'] <- 'high'
  names(keyvals)[keyvals == 'black'] <- 'mid'
  names(keyvals)[keyvals == 'royalblue'] <- 'low'
  EnhancedVolcano(res2,
    lab = rownames(res2),
    x = 'log2FoldChange',
    y = 'pvalue',
    selectLab = rownames(res2)[which(names(keyvals) %in% c('high', 'low'))],
    xlim = c(-6.5,6.5),
    xlab = bquote(~Log[2]~ 'fold change'),
    title = 'Custom colour over-ride',
    pCutoff = 10e-14,
    FCcutoff = 1.0,
    pointSize = 3.5,
    labSize = 3.5,
    shape = c(6, 4, 2, 11),
    colCustom = keyvals,
    colAlpha = 1,
    legendPosition = 'left',
    legendLabSize = 15,
    legendIconSize = 5.0,
    drawConnectors = TRUE,
    widthConnectors = 0.5,
    colConnectors = 'grey50',
    gridlines.major = TRUE,
    gridlines.minor = FALSE,
    border = 'partial',
    borderWidth = 1.5,
    borderColour = 'black') +

  scale_colour_manual(
    values = c(
      high = 'gold',
      mid = 'black',
      low = 'royalblue'),
    labels = c(
      high = expression(italic(high)),
      mid = expression(italic(mid)),
      low = expression(italic(low))))

kkk

ADD REPLY
1
Entering edit mode

It works now! Thank you so much! I really appreciate it.

ADD REPLY

Login before adding your answer.

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