ATpoint made me try this! Unfortunately, it is not as easy with EnhancedVolcano, and I may suggest a customised way via ggplot2, as per ATpoint's code.
Credit to Carlo Yague for the left and right arrow codes.
From the vignette (https://github.com/kevinblighe/EnhancedVolcano):
library(EnhancedVolcano)
library(airway)
library(magrittr)
data('airway')
airway$dex %<>% relevel('untrt')
ens <- rownames(airway)
library(org.Hs.eg.db)
symbols <- mapIds(org.Hs.eg.db, keys = ens,
column = c('SYMBOL'), keytype = 'ENSEMBL')
symbols <- symbols[!is.na(symbols)]
symbols <- symbols[match(rownames(airway), names(symbols))]
rownames(airway) <- symbols
keep <- !is.na(rownames(airway))
airway <- airway[keep,]
library(DESeq2)
dds <- DESeqDataSet(airway, design = ~ cell + dex)
dds <- DESeq(dds, betaPrior=FALSE)
res <- results(dds,
contrast = c('dex','trt','untrt'))
res <- lfcShrink(dds,
contrast = c('dex','trt','untrt'), res=res, type = 'normal')
p1 <- EnhancedVolcano(res,
lab = rownames(res),
x = 'log2FoldChange',
y = 'pvalue',
drawConnectors = TRUE,
legendPosition = 'none')
Now, for the new volcano, where absolute log2 FC 2.5 is our cut-off for display purposes:
res.new <- res
cutoff <- 2.5
# identify genes that pass the threshold of 2.5
up <- rownames(subset(res, log2FoldChange >= cutoff))
up
down <- rownames(subset(res, log2FoldChange <= cutoff * -1))
down
# impute log2 FCs in the object to be max 2.5 or min -2.5
res.new$log2FoldChange <- ifelse(res.new$log2FoldChange >= cutoff, cutoff,
ifelse(res.new$log2FoldChange <= cutoff * -1, cutoff * -1,
res.new$log2FoldChange))
max(res.new$log2FoldChange, na.rm = TRUE)
min(res.new$log2FoldChange, na.rm = TRUE)
# custom shapes for the points
customshape <- rep(19, nrow(res.new))
names(customshape) <- rep('group1', nrow(res.new))
customshape[which(rownames(res.new) %in% up)] <- -9658
names(customshape)[which(rownames(res.new) %in% up)] <- 'group2'
customshape[which(rownames(res.new) %in% down)] <- -9668
names(customshape)[which(rownames(res.new) %in% down)] <- 'group3'
# custom sizes for the points
customsize <- rep(2.0, nrow(res.new))
customsize [which(rownames(res.new) %in% up)] <- 8
customsize [which(rownames(res.new) %in% down)] <- 8
p2 <- EnhancedVolcano(res.new,
lab = rownames(res.new),
x = 'log2FoldChange',
y = 'pvalue',
drawConnectors = TRUE,
shapeCustom = customshape,
legendPosition = 'none',
pointSize = customsize,
xlim = c(-2.5,2.5))
Now draw the 2 plots:
cowplot::plot_grid(p1, p2, ncol = 2)
See this section of vignette: https://bioconductor.org/packages/release/bioc/vignettes/EnhancedVolcano/inst/doc/EnhancedVolcano.html#modify-cut-offs-for-log2fc-and-p-value-specify-title-adjust-point-and-label-size
Thanks very much for taking the time to reply. Sorry if this is a silly question, but I had a look at that part of the vignette and I still wasn’t sure how to achieve what I’m looking for (i.e. open triangles to represent outliers that fall outside of the plot window). Would be very grateful for any guidance!
There is no equivalent function in EnhancedVolcano for this. I would suggest that you simply modify the limits of the x axis via
xlim
, or, if you want to genuinely reproduce this functionality in EnhancedVolcano, you could achieve it by modifying the underlying log [base 2] fold change values in your input object for these points, and also change their shape to be open triangles.It's obviously quite difficult to account for every eventuality, and the EnhancedVolcano function / package is already 'parameter overloaded'. I am tentative about doing any further modifications.
Hi, thanks for your reply. I totally get it. Regardless, it's a fantastic package and very intuitive, particularly for a novice like myself. Thank you for making it!
No problem. You could try the solution by ATpoint (below) and adapt it to make a volcano, but, then, one can begin to see how there is a learning curve with ggplot2's 'unique' format.