novicegeek
novicegeek

Reputation: 773

Different colors of points in Volcano plot using R

This is quick a simple question and I am not able to somehow get the desired result. I want to construct a volcano plot, which I was able to do. Here is the code:

CSCJFCTable <- read.table("volcano_plot_valuesCSCJ.csv", header = TRUE, sep = ",") 
with(CSCJFCTable, plot(log2.FC., -log10(raw.pval), pch=20, main=""))
abline(h = 1.0, col = "blue
", lty = 2, lwd = 1)
abline(v = c(-1,1), col = "blue
", lty = 2, lwd = 1)
with(subset(CSCJFCTable, X.log10.p.<1.0), points(log2.FC., -log10(raw.pval), pch=20, col="gray"))
with(subset(CSCJFCTable, abs(log2.FC.)>1), points(log2.FC., -log10(raw.pval), pch=20, col="orange"))

And, here is the resulting plot enter image description here

I want to change the color of points in the first box and the third box to two different colors. So, basically, log2.FC. < -1 & -log10(raw.pval) > 1.0 should have a color say red and log2.FC. > 1 & -log10(raw.pval) > 1.0 should have a color green. And, all the points below -log10(raw.pval) = 1.0 should be gray. How can I do this? I tired different combinations but it did not work.

Upvotes: 3

Views: 6864

Answers (1)

novicegeek
novicegeek

Reputation: 773

I finally got the desired solution:

CSCJFCTable <- read.table("volcano_plot_valuesCSCJ.csv", header = TRUE, sep = ",") 
with(CSCJFCTable, plot(log2.FC., -log10(raw.pval), pch=20, main=""))
abline(h = 1.0, col = "blue
", lty = 2, lwd = 1)
abline(v = c(-1,1), col = "blue
", lty = 2, lwd = 1)
with(subset(CSCJFCTable, X.log10.p.<1.0), points(log2.FC., -log10(raw.pval), pch=20, col="gray"))
with(subset(CSCJFCTable, log2.FC.< -1 & X.log10.p.>1.0), points(log2.FC., -log10(raw.pval), pch=20, col="red"))


with(subset(CSCJFCTable, log2.FC.> 1 & X.log10.p.>1.0), points(log2.FC., -log10(raw.pval), pch=20, col="green"))

enter image description here

Upvotes: 1

Related Questions