This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to change colour of points in volcano plot by common genes?

this is my code to draw volcano plot. but i need to give green dots color for genes in up; red ones for genes in down. how can i do?

  down<- intersect(down_our$hgnc_symbol,down_pre$Gene)
  up<-intersect(up_our$hgnc_symbol,up_pre$Gene)
  res <- read.table(file = "path for csv", header=TRUE, sep = ",")
  png("diffexpr-volcanoplot-mm-ourpipeline1.png", 1200, 1000, pointsize=20)

 # Make a basic volcano plot
  with(res, plot(log2FoldChange, -log10(pvalue), pch=20, main="Volcano plot", xlim=c(-2.5,2)))

 # Add colored points: red if padj<0.05&log2FC<1, green if padj<0.05&log2FC>1
      with(subset(res , padj<.05), points(log2FoldChange, -log10(pvalue), pch=20,col="black"))
      with(subset(res, (log2FoldChange)>1), points(log2FoldChange, -log10(pvalue), pch=20, col="green"))
      with(subset(res, padj<.05 & (log2FoldChange)<1), points(log2FoldChange, -log10(pvalue), pch=20, col="red"))
      dev.off()
volcano plot rna-seq log2fc deseq2

i will look for this link. and i am already using the col argument in my code but the problem the things i would like to color is in different dataframe..

1 answer

library(airway)
library(magrittr)
data("airway")
airway$dex %<>% relevel("untrt")

library("DESeq2")
dds <- DESeqDataSet(airway, design = ~cell + dex)
dds <- DESeq(dds, betaPrior = FALSE)
res <- results(dds, contrast = c("dex", "trt", "untrt"))

first way

with(res, plot(log2FoldChange, -log10(pvalue), pch=20, main="Volcano plot"))

with(subset(res , padj<.05), points(log2FoldChange, -log10(pvalue), pch=20,col="black"))
with(subset(res, (log2FoldChange)>1), points(log2FoldChange, -log10(pvalue), pch=20, col="green"))
with(subset(res, padj<.05 & (log2FoldChange)<(1*-1)), points(log2FoldChange, -log10(pvalue), pch=20, col="red"))

h

-----------------------------------------------

second way

up <- rownames(res)[which(res$log2FoldChange>1)]
down <- rownames(res)[which(res$log2FoldChange<(1*-1))]

with(res, plot(log2FoldChange, -log10(pvalue), pch=20, main="Volcano plot"))

with(subset(res , padj<.05), points(log2FoldChange, -log10(pvalue), pch=20,col="black"))
with(res[which(rownames(res) %in% up),], points(log2FoldChange, -log10(pvalue), pch=20, col="green"))
with(res[which(rownames(res) %in% down),], points(log2FoldChange, -log10(pvalue), pch=20, col="red"))

5

Kevin

Log in to answer this question.