Skip to content

Instantly share code, notes, and snippets.

@stephenturner
Last active May 13, 2021 20:11
Show Gist options
  • Save stephenturner/4a599dbf120f380d38e7 to your computer and use it in GitHub Desktop.
Save stephenturner/4a599dbf120f380d38e7 to your computer and use it in GitHub Desktop.
code from blog post to make a volcano plot
# Download the data from github (click the "raw" button, save as a text file called "results.txt").
# https://gist.github.com/stephenturner/806e31fce55a8b7175af
res <- read.table("results.txt", header=TRUE)
head(res)
# 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, orange of log2FC>1, green if both)
with(subset(res, padj<.05 ), points(log2FoldChange, -log10(pvalue), pch=20, col="red"))
with(subset(res, abs(log2FoldChange)>1), points(log2FoldChange, -log10(pvalue), pch=20, col="orange"))
with(subset(res, padj<.05 & abs(log2FoldChange)>1), points(log2FoldChange, -log10(pvalue), pch=20, col="green"))
# Label points with the textxy function from the calibrate plot
library(calibrate)
with(subset(res, padj<.05 & abs(log2FoldChange)>1), textxy(log2FoldChange, -log10(pvalue), labs=Gene, cex=.8))
@DimitriosManias
Copy link

Hello! I have a problem in highlighting the significant genes. When I am using your data set, everything goes fine. But when I am trying with my data set I color the whole volcano plot red/orange. I have named everything exactly as here but still doesn't work. I checked my data set and it does contain genes with p.adj.values<.05. Do you have any idea why is this happening?
Btw we have tried with both csv and txt files, with two different computers, two different people but always the same annoying result!

@manajit-das
Copy link

Thanks

@ligrossman
Copy link

When labeling points, is there a way to keep the labels from overlapping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment