有小伙伴发了一张图,是关于富集分析的,只不过展示和我们之前的不太一样,是桑基图+气泡图的形式,特点就是GO terms和其对应的关键基因用桑基图展示,GO结果用气泡图展示。这幅图在很多在线生信工具中都有,很方便就能完成。本来是不想做了,但是很巧,又在别的文献中看到了,所以做一下,还是比较新奇的,至少我是第一次见。桑基图+气泡图组合,最后修饰一下即可。

setwd("D:/KS项目/公众号文章/桑基图结合富集分析图")
library(tidyverse)
# devtools::install_github("davidsjoberg/ggsankey")
library(ggsankey)
library(ggplot2)
install.packages("cols4all")
library(cols4all)
先做桑基图,作图数据的话是我们GO富集的结果,自己整理数据,至于每个Trems展示的基因可以选择对自己研究展示关键的基因。
df <- read.csv("df.csv", header = T)
df1 <- df[,-1]
colnames(df1)
df1_trans <- df1 %>%make_long(gene, pathway)
df1_trans$node <- factor(df1_trans$node,levels = c(df1$pathway %>% unique()%>% rev(),
df1$gene %>% unique() %>% rev()))
colnames(df1_trans)
ggplot(df1_trans, aes(x = x,
next_x= next_x,
node= node,
next_node= next_node,
fill= node,
label= node)) +
geom_sankey(flow.fill="#DFDFDF",
flow.color="grey60",
node.fill=dittoColors()[1:44],
width=0.15) +
geom_sankey_text(size = 3,
color= "black",
hjust=1) +
theme_void()

修饰一下:关键通路可以标注出来。
p1 = ggplot(df1_trans, aes(x = x,
next_x= next_x,
node= node,
next_node= next_node,
fill= node,
label= node)) +
geom_sankey(flow.fill="#DFDFDF",
flow.color="grey60",
node.fill=dittoColors()[1:44],
width=0.15) +
geom_sankey_text(size = 3,
color= c(rep("black",30),"red","red",rep("black",12)),
hjust=1) +
theme_void()

假设是KEGG的话,可以展示多级分类:
#展示通路
df2 <- df[,-2]
df2_trans <- df2 %>%make_long(sub_path, pathway)
#作图
ggplot(df2_trans, aes(x = x,
next_x= next_x,
node= node,
next_node= next_node,
fill= node,
label= node)) +
scale_fill_manual(values = dittoColors())+
geom_sankey(width=0.15) + #node的宽度
geom_sankey_text(size = 3,
color= "black") +
theme_void()+
theme(legend.position = "none")

接下来,做一个气泡图,这个很简单了:
enrich <- read.csv("Enrichment.csv", header = T)
colnames(enrich)
enrich$Log.q.value. <- -enrich$Log.q.value.
enrich$Description <- factor(enrich$Description, levels = enrich$Description %>% rev())
p2 = ggplot(enrich, aes(Generatio, Description, color=Log.q.value.))+
geom_point(aes(size=Count))+
scale_color_gradient(low='#14B3FF',high='#E42A2A',name = "-Log(q-value)")+
theme_bw()+
theme(axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.x = element_text(colour = 'black',size = 10),
axis.title.x = element_text(colour = 'black',size = 12),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())

最后结合二者,用AI修饰一下就达到效果了。觉得分享有的点个赞再走呗!
网友评论