ggplot2画火山图

用ggplot2画火山图看代码似乎还是很简单,但是真的来画了,细节还是蛮多的。 把代码写在这里,以便以后用。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 library(ggplot2) library(Cairo) # 读取数据 data <- read.delim("./data/g1_VS_g3.txt",header = T,sep="\t",na.strings = "") # 设置颜色域 datathreshold = as.factor(datapvalues < 0.05 & abs(log2(data$foldchange)) >=1.5) Cairo(file="volcan_PNG_300_dpi.png", type="png", units="in", bg="white", width=8, height=6, pointsize=12, dpi=300) ggplot(data=data, aes(x=log2(foldchange), y =-log10(pvalues), colour=threshold)) + geom_point(alpha=0.4, size=1.75) + xlim(c(-4, 4)) + xlab("log2 fold change") + ylab("-log10 p-value") + ggtitle("Volcano picture of DEG")+ theme_gray() + geom_vline(xintercept=c(-1.5,1.5),lty=4,col="grey",lwd=0.5)+ geom_hline(yintercept = -log10(0.05),lty=4,col="grey",lwd=0.5)+ theme(legend.position="none") # 在x轴-1.5与1.5的位置画两根竖线, 在p-value 0.05的位置画一根横线 dev.off() 这只是一个粗略的图,要细致,还需要调整网格,坐标轴,颜色,字体大小。 ...

2017-04-17 · 2 min · 波比