R语言——GSEV可视化

环境加载

注意这里面一些参数现在我还没有完全运行好,因此需要注意。
# 清空变量
remove(list = ls())

# 加载所需R包
library(clusterProfiler)
library(ggplot2)

加载GSEA结果,以便用于后续可视化

load(file = "data/gsea_result.Rda")

气泡图

########## 气泡图:dotplot ##########
tiff(file="figures/GSEA_GO_dotplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
dotplot(gsego, showCategory=30) + ggtitle("dotplot for GSEA")
dev.off()

dotplot(gsekk, showCategory=30)
dotplot(gsegmt, showCategory=30)

网络图

########## 网络图:cnetplot ##########
tiff(file="figures/GSEA_KEGG_cnetplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
cnetplot(gsekk, categorySize="pvalue", foldChange=geneList)
dev.off()

cnetplot(gsekk, foldChange=geneList)
cnetplot(gsekk, foldChange=geneList, circular = TRUE, colorEdge = TRUE)

热图

########## 热图:heatplot ##########
tiff(file="figures/GSEA_GO_heatplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
heatplot(gsego, foldChange=geneList)
dev.off()

富集图

########## 富集图:emapplot ##########
tiff(file="figures/GSEA_GO_emapplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
emapplot(gsego, pie_scale=1.5,layout="kk") #enrich map,这种图很少用了
dev.off()

高级venn图

########## 高级venn图:upsetplot ##########
library(ggupset)
library(enrichplot)
tiff(file="figures/GSEA_KEGG_upsetplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
upsetplot(gsekk) 
dev.off()

GSEA图

########## GSEA图:gseaplot、gseaplot2、gsearank ##########

GSEA图:gseaplot

gseaplot(gsekk, geneSetID = 1, by = "runningScore", title = gsekk$Description[1])#runningScore光展示下面一个图
gseaplot(gsekk, geneSetID = 1, by = "preranked", title = gsekk$Description[1])#preranked光展示上面一个图

tiff(file="figures/GSEA_KEGG_gseaplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
gseaplot(gsekk, geneSetID = 1, title = gsekk$Description[1])#geneSetID的1和gsekk$Description[1]的1是对应的
dev.off()

GSEA图:gseaplot2

gseaplot2(gsekk, geneSetID = 1, title = gsekk$Description[1])

## 在一个gsea图上绘制多个基因集
gseaplot2(gsekk, geneSetID = 1:3)#绘制三个基因集
gseaplot2(gsekk, geneSetID = 1:3, subplots = 1)#绘制第一部分
gseaplot2(gsekk, geneSetID = 1:3, subplots = 1:2)#绘制两部分

tiff(file="figures/GSEA_KEGG_gseaplot2.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
gseaplot2(gsekk, geneSetID = 1:3, subplots = 1:3,#geneSetID,gsekk中富集到的基因集编号,1:3表示前三个
          pvalue_table = TRUE,
          color = c("#E495A5", "#86B875", "#7DB0DD"), #指定颜色
          ES_geom = "dot")#line 连线图;dot虚线图
dev.off()

GSEA图:gsearank 不常用图

gsearank(gsekk, 1, title = gsekk[1, "Description"])

pp <- lapply(1:3, function(i) {
  anno <- gsekk[i, c("NES", "pvalue", "p.adjust")]
  lab <- paste0(names(anno), "=",  round(anno, 3), collapse="\n")
  
  gsearank(gsekk, i, gsekk[i, 2]) + xlab(NULL) +ylab(NULL) +
    annotate("text", 0, gsekk[i, "enrichmentScore"] * .9, label = lab, hjust=0, vjust=0)
})
tiff(file="figures/GSEA_KEGG_gsearank.tiff",
     width = 35,height = 40,units ="cm",
     compression="lzw",bg="white",res=300)
plot_grid(plotlist=pp, ncol=1)
dev.off()
########## 山脊图:ridgeplot ##########
tiff(file="figures/GSEA_KEGG_ridgeplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
ridgeplot(gsekk)
dev.off()

tiff(file="figures/GSEA_GO_ridgeplot.tiff",
     width = 35,height = 22,units ="cm",
     compression="lzw",bg="white",res=300)
ridgeplot(gsego)
dev.off()

版权声明:本文为codyliu_bo原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。