输入数据格式
pathway = read.table("kegg.result",header=T,sep="\t")
pp = ggplot(pathway,aes(richFactor,Pathway)) #Pathwy是ID,richFactor是富集的基因数目除以背景的基因数目
# 改变点的大小
pp + geom_point(aes(size=R0vsR3)) # 以基因的数目表示点大小
pbubble = pp + geom_point(aes(size=R0vsR3,color=-1*log10(Qvalue))) # 显著性表示颜色
# 自定义渐变颜色
pbubble + scale_colour_gradient(low="green",high="red")
# 绘制pathway富集散点图
pr = pbubble + scale_colour_gradient(low="green",high="red") + labs(color=expression(-log[10](Qvalue)),size="Gene number",x="Rich factor",y="Pathway name",title="Top20 of pathway enrichment")
# 改变图片的样式(主题)去除背景色
pr + theme_bw()
#去除网格线
p_remove_grid <- pr +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
#网格线颜色
panel.grid=element_line(color='grey')
首先需要安装ggplot2
library(ggplot2) #导入ggplot2
x <- read.table("c:/Users/yueyao/Desktop/pathwayenrichment.txt",head = T, sep = "\t") #读入文件,我的文本文件在桌面
pdf(file="c:/Users/yueyao/Desktop/pathway_enrichment.pdf",width=10,height=10)#生成输出文件,双引号里面为路径及文件名,可自行设置
png(file="c:/Users/yueyao/Desktop/pathway_enrichment.png",width=800,height=800)
p <- ggplot(x,aes(x$Rich.Factor,x$Pathway))#作图利用的两列数据
map = p + geom_point(aes(size=x$Genes,colour=x$Qvalue))+theme(axis.text=element_text(color='black'),axis.text.y=element_text(size=14),axis.text.x=element_text(size=14),panel.background=element_rect(fill='transparent'),panel.grid=element_line(color='grey'),panel.border=element_rect(fill='transparent',color='black'),axis.title=element_text(size=16)) +labs(color="Qvalue",size="Gene number",x="Rich factor",y="Pathway name",title="Top20 of pathway enrichment")
map
dev.off()
输出图片