R语言学习之GO富集分析结果可视化(柱状图、网络图)

读取gene symbol

library(clusterProfiler)

library(org.Hs.eg.db)

input <- read.table("gene.csv",sep = ",",header = T)

把symbol转换为ENTREZID

genetransform <- bitr(input$target,

              fromType = "SYMBOL",

              toType = c("ENSEMBL","ENTREZID"),

              OrgDb =org.Hs.eg.db )

#注意:此处物种是人类

GO富集分析

Go <- enrichGO(gene = genetransform$ENTREZID,

                OrgDb = org.Hs.eg.db,

                pvalueCutoff =0.05,

                qvalueCutoff =0.05,

                readable = TRUE)

head(Go)

将GO富集结果写出到文件

write.table(Go,file="GO RESULT.txt",sep="\t",

            quote=F,row.names = F)

#把结果保存为R数据。

save(Go,file ="Go result.Rda" )

###################################################################

绘制柱状图

library(ggplot2)

library(org.Hs.eg.db)

library(clusterProfiler)

library(cowplot)

画图

barplot(Go,showCategory=20,color="pvalue")

导出图

tiff(file="Go image.tiff",width=35,height = 22,units = "cm",

    compression = "lzw",bg="white",res=300)

barplot(Go,showCategory=20,color="pvalue")

dev.off()

####################################################################

绘制网络图

library(ggplot2)

library(org.Hs.eg.db)

library(clusterProfiler)

library(cowplot)

install.packages("ggnewscale")

library(ggnewscale)

cnetplot(Go,circular=T,colorEdge=T)

你可能感兴趣的:(R语言学习之GO富集分析结果可视化(柱状图、网络图))