輸入數據格式
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()
輸出圖片