我有这行代码:
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")
导致火山阴谋;但是我想找到一种方法,我可以用红色点> log(2)和
编辑: 好的,作为一个例子,我试图做以下事情来获得火山阴谋:
install.packages("ggplot2")
然后
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)
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")
我想要做的是为logFC值着色&gt; 2和蓝色的logFC值&lt; -2
答案 0 :(得分:1)
您需要添加一个报告标签的阈值列 logFC值&gt; 2,logFC值&lt; -2,和之间的值:
mydata<-mydata%>%mutate(threshold = ifelse(logFC >= 2,"A", ifelse(logFC<=-2 , "B", "C")))
接下来,您将编写火山图并按geom_point
和scale_colour_manual
指定颜色。作为logFC&lt; = - 2的标签的B是蓝色
ggplot(mydata, aes(x=logFC, y=log10)) +
geom_point(aes(colour = threshold), size=2.5) +
scale_colour_manual(values = c("A"= "yellow", "B"="blue", "C"= "black"))
答案 1 :(得分:0)
您需要使用col
参数,类似的应该这样做:
# 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")