很久很久以前,看到過文章中的KEGG富集可視化結(jié)果圖。是對(duì)KEGG通路進(jìn)行注釋的。后來在一些測序公司的宣傳頁上也見到過類似的圖:


其實(shí)這個(gè)圖就是多了一個(gè)KEGG通路注釋,近期也有小伙伴尋求怎么做。網(wǎng)上很多在線工具可以完成這個(gè)圖,只需要按照相應(yīng)的示例提供數(shù)據(jù)就可以一鍵出圖,很方便。用到的數(shù)據(jù)就是分析完成的KEGG富集通路,關(guān)鍵的兩列一個(gè)是KEGG同類名稱,一列是counts,當(dāng)然這個(gè)counts也可以選擇展示怕值。例如這里的這個(gè)網(wǎng)站:https://www.bioinformatics.com.cn/plot_basic_pathway_enrichment_categorical_bar_plot_124
出圖的效果如下:

當(dāng)然我們還是希望自己動(dòng)手做出來,畢竟也不是什么難事。需要的文件一個(gè)是我們分析的富集通路文件,另外一個(gè)就是KEGG注釋分類,這個(gè)文件在KEGG官網(wǎng)可以整理,這里我們已上傳分享到QQ群文件了,可自行下載!
首先加載包和數(shù)據(jù),做一個(gè)普通的柱狀圖很簡單:
# setwd('D:/KS項(xiàng)目/公眾號(hào)文章/KEGG通路注釋')
library(dplyr)
library(ggplot2)
library(forcats)
library(dittoSeq)
kegg <- read.csv('KEGG.csv', header = T)
#其實(shí)做一個(gè)柱狀圖沒有什么難度
ggplot(kegg,aes(Description, Gene.Count))+
geom_bar(stat = "identity")+
geom_text(aes(label=Gene.Count, y=Gene.Count+2),size=3)+
coord_flip()+
labs(x='',y='Gene count')+
theme_bw()+
theme(panel.grid = element_blank(),
legend.position = 'none',
axis.ticks.y = element_blank(),
axis.text = element_text(colour = 'black', size = 10))

然后讀入注釋文件,將通路注釋,這里使用的笨辦法,直接篩選:
#注釋文件
kegg_ann <- read.csv('kegg_annotation.csv')
rownames(kegg_ann) <- kegg_ann$directory3
df <- kegg_ann[kegg$Description,]
kegg1 <- cbind(kegg, df)
table(kegg1$directory1)
# Cellular Processes Environmental Information Processing
# 1 3
# Human Diseases Metabolism
# 3 3
# Organismal Systems
# 2
kegg1 <- kegg1[order(kegg1$directory1),]
kegg1$Description <- as.factor(kegg1$Description)
kegg1$Description <- fct_reorder(kegg1$Description)
p <- ggplot(kegg1,aes(Gene.Count,Description))+
geom_bar(stat = "identity", aes(fill=directory1))+
geom_text(aes(label=Gene.Count, x=Gene.Count+2),size=3)+
labs(y='',x='Gene count')+
theme_classic()+
theme(panel.grid = element_blank(),
legend.position = 'none',
axis.ticks.y = element_blank(),
axis.text = element_text(colour = 'black', size = 10),
plot.margin = margin(0,0,0,-0.05, "cm"))+
scale_fill_manual(values = dittoColors())
最后添加上右側(cè)的注釋就完成了:
#構(gòu)建注釋
df1<-data.frame(x="A", y=kegg1$Description, group=kegg1$directory1)
df1$group <- factor(df1$group, levels = c("Organismal Systems",
"Metabolism",
"Human Diseases",
"Environmental Information Processing",
"Cellular Processes"))
p1 <- ggplot(df1,aes(x,y, fill=group))+
geom_tile(show.legend = F)+
facet_grid(group~.,scales = 'free',space = 'free')+
labs(x=NULL,y=NULL)+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0))+
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
plot.margin = margin(0,-0.05,0,0, "cm"),
strip.text.y = element_text(angle=0,size=10,color = "black",
hjust = 0,margin = margin(b = 3,t=3)),
strip.background = element_rect(colour=NULL,fill = 'white'),
panel.spacing=unit(0, "mm"))+
scale_fill_manual(values = c("#0072B2","#F0E442","#009E73","#56B4E9","#E69F00"))
#拼圖
library(deeptime)
ggarrange2(p, p1,nrow = 1,widths =c(2,0.05))

當(dāng)然了,網(wǎng)上也有別的形式的注釋,這里不再演示,大概樣子就是在柱狀圖y軸添加了分類的名稱,有了注釋文件就可以構(gòu)造了。具體的做法可以參考我們之前的帖子:柱狀圖|GO、KEGG|標(biāo)簽與柱狀圖顏色對(duì)應(yīng)。
那么最后還有一個(gè)問題,很多人肯定會(huì)想到,就是GO的結(jié)果可以注釋嘛?我們知道GO分為BP、MF、CC三個(gè),但是在BP中能不能繼續(xù)注釋,我是沒有看到官方的文件,但是需要自己注釋和作圖可以參考我們這個(gè)帖子。希望分享對(duì)你有幫助,點(diǎn)個(gè)贊、分享下再走唄!