GO 与KEGG分析,调整坐标及其字体大小

1 整理表格,使symbol转entrezid,利于后面的富集分析。

rm(list = ls())
options(stringsAsFactors = F)

#读取csv

x=read.csv('mRNAvol.csv',header = T)

#读取excel

library(readxl)
mRNA = read_excel("互作表.xlsx",sheet = 2) 
y=as.data.frame(mRNA)

library(dplyr)

deg <- inner_join(x,y,by=c("GeneSymbol"="gene"))

##4.加ENTREZID列,用于富集分析(symbol转entrezid,然后inner_join)
library(ggplot2)
library(clusterProfiler)
library(org.Hs.eg.db)
library(dplyr)
s2e <- bitr(deg$GeneSymbol, 
            fromType = "SYMBOL",
            toType = "ENTREZID",
            OrgDb = org.Hs.eg.db)#人类
#其他物种http://bioconductor.org/packages/release/BiocViews.html#___OrgDb
deg1 <- inner_join(deg,s2e,by=c("GeneSymbol"="SYMBOL"))

2 GO 分析

BP,MF and CC分别作图

erich.go.CC = enrichGO(gene = deg1$ENTREZID,
                       
                       OrgDb = org.Hs.eg.db,
                       
                       keyType = "ENTREZID",
                       
                       pAdjustMethod = "BH",
                       
                       ont = "CC",
                       
                       pvalueCutoff = 0.5,
                       
                       qvalueCutoff = 0.5,
                       
                       readable=T)

## 画图

barplot(erich.go.CC)

ggsave("3lnc-erich.go.CC.png")

#生物过程

erich.go.BP = enrichGO(gene = deg1$ENTREZID,
                       
                       OrgDb = org.Hs.eg.db,
                       
                       keyType = "ENTREZID",
                       
                       ont = "BP",
                       
                       pvalueCutoff = 0.5,
                       
                       qvalueCutoff = 0.5,
                       
                       readable=T)

##分析完成后,作图

barplot(erich.go.BP)

#分子功能:

ego_MF <- enrichGO(gene = deg1$ENTREZID,
                   
                   OrgDb= org.Hs.eg.db,
                   
                   keyType = "ENTREZID",
                   
                   ont = "MF",
                   
                   pvalueCutoff = 0.5,
                   
                   qvalueCutoff = 0.5)

barplot(ego_MF)

3 GO 分析,直接做3图拼图,一步完成

ALL <- enrichGO(gene=deg1$ENTREZID,
                
                OrgDb=org.Hs.eg.db,
                
                keyType = "ENTREZID",
                
                ont = 'ALL',
                
                pvalueCutoff = 0.5,
                
                pAdjustMethod = "BH",
                
                qvalueCutoff = 0.5,
                
                readable=T)

save(ALL,file = "3-lnc-GO-直接作图.Rdata")



#BB,CC,MF全部显示出来

#条形图

barplot(ALL, split="ONTOLOGY")+ facet_grid(ONTOLOGY~.,scale="free")

#泡泡图

dotplot(ALL,font.size=15, split="ONTOLOGY")+ facet_grid(ONTOLOGY~.,scale="free")

ALLGO <- as.data.frame(ALL@result)

write.csv(as.data.frame(ALL@result), file="GOALL-3lnc-mRNA.csv",quote=FALSE)

注:dotplot 与barplot中均可加字体大小 font.size=15

4 KEGG

#KEGG
kk.all <- enrichKEGG(gene = deg1$ENTREZID,
                     
                     organism = 'hsa',
                     
                     #universe = gene_all,
                     
                     pvalueCutoff = 0.5,
                     
                     qvalueCutoff =0.5)#P值或者Q值阈值可以根据富集的结果进行主观修改



save(kk.all,file = "lncBCA-kegg-直接作图.Rdata")

dotplot(kk.all)#气泡图

barplot(kk.all)#条形图

字体及其气泡大小,字体折叠

 #字体大小,显示项数,标题,泡泡大小,需加载ggplot2
dotplot(kk.all, font.size=20, showCategory=10, title="Enrichment KEGG Top10") + scale_size(rang=c(5.20))
 #文本太长超出的解决方案
library(stringr)
library(ggplot2)
barplot(All)+scale_x_discrete(labels=function(x) str_wrap(x,width=10))
dotplot(All)+scale_y_discrete(labels=function(x) stringr::str_wrap(x, width=60))

你可能感兴趣的:(GO 与KEGG分析,调整坐标及其字体大小)