绘出后的图如下:
首先设立一个工作文件夹,里面放数据输入文件,格式如图
####下面是有关代码
#install.packages("ggplot2")
#三列信息需要的
#Term: GO或者通路名称
#Count: 富集在每个term的基因数目
#FDR: 矫正后的pֵ
library(ggplot2) #引用包
inputFile="input.txt" #输入
outFile="barplot.pdf" #输出
rt = read.table(inputFile, header=T, sep="\t", check.names=F) #读取
#Term按FDR排序
labels=rt[order(rt$FDR,decreasing =T),"Term"]
rt$Term = factor(rt$Term,levels=labels)
#绘制
p=ggplot(data=rt)+geom_bar(aes(x=Term, y=Count, fill=FDR), stat='identity')+
coord_flip() + scale_fill_gradient(low="red", high = "blue")+
xlab("Term") + ylab("Gene count") +
theme(axis.text.x=element_text(color="black", size=10),axis.text.y=element_text(color="black", size=10)) +
scale_y_continuous(expand=c(0, 0)) + scale_x_discrete(expand=c(0,0))+
theme_bw()
ggsave(outFile,width=7,height=5) #保存图片
#########################
下面有演示代码和演示用的数据文件
链接:https://pan.baidu.com/s/1Reia1v0-Mp1zBARetdt6-g
提取码:ch8o
--来自百度网盘超级会员V4的分享