富集分析气泡图dotplot, 本脚本只需要一个表格数据(如果是clusterProfiler包输出的富集分析结果可直接使用),也可以是其他软件工具的结果,按需改成本脚本所需格式即可。
Description | pvalue | Count | GeneRatio | |
---|---|---|---|---|
GO:0023061 | signal release | 5.246744e-06 | 29 | 0.06 |
GO:0050673 | epithelial cell proliferation | 6.129368e-06 | 27 | 0.06 |
GO:0045444 | fat cell differentiation | 7.622508e-06 | 18 | 0.04 |
# Dotplot 气泡图
library(tidyverse)
DEG_Dotplot <- function(df, title="") {
# """
# data格式如下(需有Description,pvalue,Count,GeneRatio列)
# !!! 其中GeneRatio必须为数值型,如下图所示,可能需要准换
# GeneRatio表示点颜色,Count表点的大小,横坐标为p值
# df表的顺序是什么,画图的顺序就是什么
# Description pvalue Count GeneRatio
#GO:0023061 signal release 5.246744e-06 29 0.06
#GO:0050673 epithelial cell proliferation 6.129368e-06 27 0.06
#GO:0045444 fat cell differentiation 7.622508e-06 18 0.04
# resultdir = './result_stringtie/p005fc15'
# filemark = 'GO_BP_top20_common'
# 此函数可能需要使用scale_x_continuous调整x轴刻度
# """
# 如果已经时数字请删除这二行代码
df$GeneRatio <- as.numeric(str_split(df$GeneRatio, pattern = '/', simplify = T)[,1])/
as.numeric(str_split(df$GeneRatio, pattern = '/', simplify = T)[,2])
dotplot <- ggplot(cbind(df, Order = nrow(df):1)) +
geom_point(mapping = aes(x = -log10(pvalue), y = Order,
size = Count, fill = GeneRatio),
shape = 21) +
scale_fill_gradientn(colours = c("grey", "gold", "red")) + #自定义配色
scale_y_continuous(position = "left",
breaks = 1:nrow(df),
labels = Hmisc::capitalize(rev(df$Description))) +
#scale_x_continuous(breaks = c(3, 4,5,6),
# #breaks = seq(0, xmax+5, 5),
# limits = c(3,6),
# expand = expansion(mult = c(.05, .05))) + #两边留空
labs(x = "-Log10(PValue)", y = NULL) +
guides(size = guide_legend(title = "Gene count"),
fill = guide_colorbar(title = "GeneRatio")) +
ggtitle(title) +
theme_bw() +
theme(panel.grid =element_blank(),
panel.grid.major = element_line(color = "gray", linetype = "dashed"),
panel.border = element_rect(color = "black", linewidth = 1),
axis.text = element_text(size = 13, family = 'Times'),
title = element_text(size = 13, family = 'Times')) #去除网格线
dotplot %>% ggplotGrob()# %>% cowplot::plot_grid()
# fname=paste0(resultdir, '/', filemark,'.pdf')
# ggsave(fname, width = 8, height = 10)
return(dotplot)
}
# if __name__ == "__main__":
keggdf <- xlsx::read.xlsx("kegg.1.xlsx", sheetIndex = 1)
range(round(-log10(keggdf$pvalue)))
#
p_df <- keggdf[1:15,]
dotplot = DEG_Dotplot(p_df, title="xx")
ggsave(file = "Dotplot_KEGG_top10.pdf", width = 8, height = 7)
#gh <- ggplotGrob(dotplot)
#gd <- ggplotGrob(dotplotk)
#cowplot::plot_grid(gh, gd, rel_widths = c(1.2, 1))
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。