用david转换成ENTREZID基因
gene<-read.csv(file="id.csv",header = T)
gene_diff<-gene$To#ENTREZID基因
kk.diff <- enrichKEGG(gene = gene_diff,
organism = 'mmu',
#可以更换物种,这是小鼠的,人类是hsa
pvalueCutoff = 0.05)
head(kk.diff)[,1:6]
dotplot(kk.diff );ggsave('kk.diff.dotplot.png')#点图
kegg_diff_dt <- as.data.frame(kk.diff)
diff_kegg<-kegg_diff_dt[kegg_diff_dt$pvalue<0.05,];diff_kegg$group=-1
对KEGG富集结果可视化
kegg_plot <- function(diff_kegg){
dat<-diff_kegg
colnames(dat)
dat$pvalue = -log10(dat$pvalue)
dat$pvalue=dat$pvalue*dat$group
dat=dat[order(dat$pvalue,decreasing =F),]
g_kegg<- ggplot(dat, aes(x=reorder(Description,order(pvalue, decreasing =T)), y=pvalue, fill=group)) +
geom_bar(stat="identity") +
scale_fill_gradient(low="blue",high="red",guide = FALSE) +
scale_x_discrete(name ="Pathway names") +
scale_y_continuous(name ="log10P-value") +
coord_flip() + theme_bw()+
theme(text = element_text(size=8),plot.title = element_text(hjust = 0.1))+
ggtitle("Pathway Enrichment")
}
g_kegg<-kegg_plot(diff_kegg)
print(g_kegg)
ggsave(g_kegg,filename = 'kegg_up_down.pdf')
画出来选定某一通路的图形
BiocManager::install("pathview")
require(pathview)
geneList<-gene#选定的基因
pathview(gene.data = "genelist", pathway.id = "hsa04110",
species="hsa",limit =list(gene=max(abs(geneList)),cpd=1))
画出来选定某一通路的图形,我们的基因集中在该通路出现的基因变成绿色显示在该通路中