Plot of volcano in R
source link: https://www.codesd.com/item/plot-of-volcano-in-r.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Plot of volcano in R
I have this line of code :
plot(gene_list$logFC, -log10(gene_list$P.Value),xlim=c(-10, 10), ylim=c(0, 15),xlab="log2 fold change", ylab="-log10 p-value")
which results in a volcano plot; however I want to find a way where I can color in red the points >log(2) and
Edit: Okay so as an example I'm trying to do the following to get a volcano plot:
install.packages("ggplot2")
and then
gene_list <- read.table("/Users/Javi/Desktop/gene_list.csv", header=T, sep=",")
require(ggplot2)
##Highlight genes that have an absolute fold change > 2 and a p-value < 0.05
gene_list$threshold = as.factor(abs(gene_list$logFC) > 2 & gene_list$P.Value < 0.05)
Construct the plot object
g = ggplot(data=gene_list, aes(x=logFC, y=-log10(P.Value), colour=my_palette)) +
geom_point(alpha=0.4, size=5) +
theme(legend.position = "none") +
xlim(c(-10, 10)) + ylim(c(0, 15)) +
xlab("log2 fold change") + ylab("-log10 p-value")
What I want to do is to color the logFC values > 2 and in blue the logFC values < -2
You need to use the col
argument, something like that should do it:
# first set up the plot
plot(gene_list$logFC, -log10(gene_list$P.Value),
xlim=c(-10, 10), ylim=c(0, 15),
xlab="log2 fold change", ylab="-log10 p-value",
type="n")
# then add the points
sel <- which(gene_list$logFD<=log(2)) # or whatever you want to use
points(gene_list[sel,"logFC"], -log10(gene_list[sel,"P.value"]),col="black")
sel <- which(gene_list$logFD>log(2)) # or whatever you want to use
points(gene_list[sel,"logFC"], -log10(gene_list[sel,"P.value"]),col="red")
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK