EnhancedVolcano: How to coloring custom gene points in volcano plot?
2
1
Entering edit mode
4.0 years ago
choijamtsm ▴ 60

Hello everyone!

I am learning to create a volcano plot by using EnhancedVolcano in R. But I am struggling to color custom points (genes).

Here is my input file:

library('EnhancedVolcano')

res <- read.table("text.txt", header=TRUE)
res$gene <- as.character(res$gene)

res object contains:

head(res)
#       gene log2foldchange    pvalue          padj
#1    Cx3cr1      -8.039239 1.29e-118 2.780000e-116
#2     Trem1      -5.258502  3.01e-44  1.770000e-42
#3 Serpina3f       3.202818  2.12e-09  2.400000e-08

Also, I have gene lists which I want to label(able to do it), and color (cannot do it) in "res$gene" object (overlapping):

gene_list <- scan("503-5ptarget.txt", what="", sep="\n")

    [1] "gene"       "Fam122A"    "Ccnd2"      "Usp2"       "Arl2"       "Rab9B"      "Dcaf7"      "Pom121"     "Ccdc42B"    "N4Bp1"      "Tmem74B"    "Akt3"

Now I created this volcano plot by injecting "gene_list" into "res$gene". But the problem was I can "label" overlapped gene, But I "cannot color that point".

aa2 <- EnhancedVolcano(res,
                       lab = res$gene,
                       x = 'log2foldchange',
                       y = 'pvalue',
                       title = 'test',
                       subtitle = "test",
                       pCutoff = FALSE,
                       FCcutoff = FALSE,
                       xlim = c(-10, 10),
                       pointSize = 2.0,
                       cutoffLineType = 'blank',
                       selectLab = gene_list,
                       labCol = 'black',
                       labFace = 'bold',
                       colAlpha = 1,
                       shade = gene_list,
                       shadeLabel = 'gene list 1',
                       shadeAlpha = 1/2,
                       shadeFill = 'red',
                       shadeSize = 1,
                       shadeBins = 5,
                       col = c('grey', 'grey','grey', 'grey'),
                       drawConnectors = TRUE,
                       gridlines.major = FALSE,
                       gridlines.minor = FALSE,
                       legendVisible = FALSE)

Here is the plot:

Rplot

How can I color these overlapped gene lists? thank you

EnhancedVolcano • 7.1k views
ADD COMMENT
0
Entering edit mode

Hi, I have the same problem than "choijamtsm", i followed the script and i'm able to put its specific name but i don't known how to change the color of a specific point, this will be very useful for me. thanks in advance

ADD REPLY
0
Entering edit mode

Can you please share the code that you have already tried? Also, please show samples of your input data (the results table)

ADD REPLY
5
Entering edit mode
4.0 years ago

Hey,

If you want to label specific genes, then you just need to use the selectLab parameter, as elaborated here:

If you want to customise the colouring of the points, then you need to follow:

A much easier way to colour-mark key genes is by following this section (but this is a relatively new feature and is not fully developed to my liking):

Kevin

ADD COMMENT
0
Entering edit mode

I followed vignette carefully but still no luck. Is there any alternative solutions to coloring point?

ADD REPLY
0
Entering edit mode

A good practice is to run through the entire vignette using the code provided [in the vignette] - you literally will not have to write any of your own code. In this process, by checking the input and output for various commands / functions, you should be able to adapt the vignette's code to your own analysis.

ADD REPLY
5
Entering edit mode
2.9 years ago

Aren't you better off building the plot yourself? I don't think it's going to be much more complicated...

Some dummy data:

library(data.table) # Not necessary but super-useful
library(ggrepel)    # This is to avoid labels overalapping each other
library(ggplot2)

gene_list <- data.table(
    gene= c('gene001', 'gene002', 'gene003', 'gene004'),
    colour= c('red', 'blue', 'orange', 'violet')
)

set.seed(123)
n <- 1000
res <- data.table(
    gene= sprintf('gene%03d', 1:n),
    log2foldchange= c(rgamma(n/2, 1, 2), -rgamma(n/2, 1, 2)),
    padj= 10^-rgamma(n, 1, 0.1)
)

Convert padj to -log10(p) and add colour choice:

res[, log10padj := -log10(padj)]

res <- merge(res, gene_list, by= 'gene', all.x= TRUE)
res
         gene log2foldchange         padj colour log10padj
   1: gene001     0.09110855 1.553255e-11    red 10.808757
   2: gene002     0.84787557 5.187897e-30   blue 29.285009
   3: gene003     0.81044009 1.754765e-15 orange 14.755781
   4: gene004     1.22404803 3.007857e-03 violet  2.521743
   5: gene005     0.43951396 4.294535e-20   <NA> 19.367084
  ---                                                     
 996: gene995    -0.74794774 8.898109e-04   <NA>  3.050702
 997: gene996    -0.28476577 4.175561e-10   <NA>  9.379285
 998: gene997    -0.09387140 1.521622e-04   <NA>  3.817693
 999: gene998    -0.99570414 1.755187e-02   <NA>  1.755677
1000: gene999    -0.73455174 2.145441e-12   <NA> 11.668483

Plot with various bells and whistles:

gg <- ggplot(data= res, aes(x= log2foldchange, y= log10padj, label= gene)) +
    geom_point(colour= 'grey80') +
    geom_point(data= res[abs(log2foldchange) > 0.5 & log10padj > 2], colour= 'grey30') +
    geom_point(data= res[!is.na(colour)], colour= 'orange') +
    geom_vline(xintercept= c(-0.5, 0.5), colour= 'blue', linetype= 'dashed') +
    geom_hline(yintercept= 2, colour= 'blue', linetype= 'dashed') +
    geom_text_repel(data= res[!is.na(colour)], colour= colour, fontface= 'bold') +
    xlab('log2 fold-change') +
    ylab('-log10(Padj)') +
    theme_classic()
ggsave('tmp.png', width= 12, height= 12, units= 'cm')

There may be different and probably better ways of doing it but hoepfully you get the idea...

enter image description here

ADD COMMENT
0
Entering edit mode

aún mejor / meglio:

plot(x, -log10(y))
ADD REPLY

Login before adding your answer.

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