RNA-seq

GO和KEGG已有数据作图

2021-04-22  本文已影响0人  萍智医信

GO数据库,全称是Gene Ontology(基因本体),他们把基因的功能分成了三个部分分别是:细胞组分(cellular component, CC)、分子功能(molecular function, MF)、生物过程(biological process, BP)。

#读取文件
rt1=read.table("subNet1.go.txt",sep="\t",check.names=F,header=T)       #读取文件
rt2=read.table("subNet1.KEGG.txt",sep="\t",check.names=F,header=T)
#加载R包
library("ggplot2")
#按照qvalue升序排序,分别选出前10个BP,CC,MF的条目(GO)
rt1_MF<-rt1[rt1$ONTOLOGY=="MF",][1:10,]
rt1_CC<-rt1[rt1$ONTOLOGY=="CC",][1:10,]
rt1_BP<-rt1[rt1$ONTOLOGY=="BP",][1:10,]
a<-rbind.data.frame(rt1_BP,rt1_CC,rt1_MF)
#按qvalue排序(GO)
labels=a[order(a$qvalue,decreasing =T),"Description"]
a$Description = factor(a$Description,levels=labels)
#绘制GO柱状图
p=ggplot(data=a)+geom_bar(aes(x=Description, y=Count, fill=qvalue),split="ONTOLOGY", stat='identity')+
  facet_grid(ONTOLOGY~., scale='free')+
  xlab("") + ylab("") +
  coord_flip() + scale_fill_gradient(high = "blue",low="red" )+
  theme(axis.text.x=element_text(color="black", size=20,face = "bold"),axis.text.y=element_text(color="black", size=20,face = "bold"),axis.title.x=element_text(color="black", size=20,face = "bold"),axis.title.y=element_text(color="black", size=20,face = "bold")) + 
  scale_y_continuous(limits = c(0,15.5)) + scale_x_discrete(expand=c(0,0))+
  theme_bw()
print(p)
ggsave(file="PPI GO.pdf",plot=p,width=8,height=6)
#绘制KEGG图
#按qvalue排序
labels=rt2[order(rt2$qvalue,decreasing =T),"Description"]
rt2$Description = factor(rt2$Description,levels=labels)
p1=ggplot(data=rt2)+geom_bar(aes(x=Description, y=Count, fill=qvalue), stat='identity')+
  xlab("") + ylab("") +
  coord_flip() + scale_fill_gradient(high = "blue",low="red" )+
  theme(axis.text.x=element_text(color="black", size=20,face = "bold"),axis.text.y=element_text(color="black", size=20,face = "bold"),axis.title.x=element_text(color="black", size=20,face = "bold"),axis.title.y=element_text(color="black", size=20,face = "bold")) + 
  scale_y_continuous(limits = c(0,8.5)) + scale_x_discrete(expand=c(0,0))+
  theme_bw()
print(p1)
ggsave(file="PPI KEGG.pdf",plot=p1,width=6,height=4)
上一篇下一篇

猜你喜欢

热点阅读