有小伙伴發(fā)了一張圖疲陕,是關于富集分析的方淤,只不過展示和我們之前的不太一樣,是商阊辏基圖+氣泡圖的形式携茂,特點就是GO terms和其對應的關鍵基因用桑基圖展示诅岩,GO結果用氣泡圖展示讳苦。這幅圖在很多在線生信工具中都有带膜,很方便就能完成。本來是不想做了鸳谜,但是很巧膝藕,又在別的文獻中看到了,所以做一下咐扭,還是比較新奇的芭挽,至少我是第一次見。苫确荆基圖+氣泡圖組合袜爪,最后修飾一下即可。
setwd("D:/KS項目/公眾號文章/裳ι粒基圖結合富集分析圖")
library(tidyverse)
# devtools::install_github("davidsjoberg/ggsankey")
library(ggsankey)
library(ggplot2)
install.packages("cols4all")
library(cols4all)
先做尚凉荩基圖,作圖數(shù)據(jù)的話是我們GO富集的結果逛绵,自己整理數(shù)據(jù)怀各,至于每個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修飾一下就達到效果了。覺得分享有的點個贊再走唄硕并!