Closed ixxmu closed 2 months ago
KEGG通路分析可视化常见的就是散点图,都快用腻了,更新一个基于 ggforce包的KEGG通路富集可视化方案,本方案中同时包括了参与通路的差异物counts、p value以及每条通路中全部差异物的整体变化情况(上调差异物多还是下调差异物多)
效果图如下:方案一:方案二:
rm(list = ls())
library(tidyverse)
#loading data
files <- fs::dir_ls("inputfile",recurse = TRUE,glob = "*.txt")
files_names <- str_extract(files,"(?<=\\/).*(?=\\.)");files_names
dat <- purrr::map_df(files,read.delim)#reading data
names(dat)
inputfile下存放keeg的通路分析结果,必要信息包括:pathway信息、每条通路上全部差异物的数量(Diff.counts)、p.value、注释到每条通路中的全部代谢物或者蛋白Total.background(差异+非差异、每条通路中上调的差异物和下调的差异物(Diff.upcounts和Diff.downcounts):
计算每条通路的差异变化丰度:(Diff.upcounts-Diff.downcounts)/Total.background
# reshaping data
dat <- dat %>%
mutate(diff.abundance = (Diff.upcounts - Diff.downcounts)/Background.counts,
x=rep(0,n=nrow(.))) %>% #diff.abundance=x.trend
slice_min(order_by =P.value,n=20) %>%
mutate(index =seq(1,20)) %>%
mutate(
group=case_when(
diff.abundance>0~"more up-reulated metabolites",
diff.abundance<0~"more down-regulated metabolites",
TRUE~"equal up- and down-regulated metabolites"
),
label=paste0("p=",round(P.value,3)," count=",Diff.counts))
人为指定geom_point中size大小:
#manual setting size
plot.kegg2 <- ggplot() +
geom_vline(xintercept = c(0),size = 0.1,color = "#1f294e")+
ggforce::geom_link(data = dat,aes(x = x,
y = reorder(pathway, -index),
xend = diff.abundance,yend = pathway,
size = after_stat(index),
alpha = after_stat(index),
color=group
),
show.legend = F)+
geom_point(data = dat,
aes(x = diff.abundance, y = pathway,color=group,
),
size=5,
shape = 21,fill = "white")+
scale_colour_manual(values =c("#492952","#00B0F0","#EE0000"))+
guides(color=guide_legend('pathway condition')
)+
geom_text(dat,mapping=aes(x=diff.abundance,y=pathway,label=label),
size =2.5,color="grey20",
hjust = 0, nudge_x = 0.05)+
theme_test()+
xlab("Differential Abundance Score")+
ylab(NULL)
#saving
ggsave("outputfile/KEGG_abundancescore2.png", width = 8, height = 4.5)
print(plot.kegg2)
ggsave("outputfile/KEGG_abundancescore2.pdf", width =8, height = 4.5,onefile=F)
print(plot.kegg2)
dev.off()
或者将geom_point中size映射到对应的通路的差异物总数上:
#mapping size to difference level
plot.kegg3 <-
ggplot() +
geom_vline(xintercept = c(0),size = 0.1,color = "#1f294e")+
ggforce::geom_link(data = dat,aes(x = x,
y = reorder(pathway, -index),
xend = diff.abundance,yend = pathway,
size = after_stat(index),
alpha = after_stat(index),
color=group
),show.legend = F)+
geom_point(data = dat,
aes(x = diff.abundance, y = pathway,color=group,
size=(Diff.counts)
),
shape = 21,fill = "white")+
scale_colour_manual(values =c("#492952","#00B0F0","#EE0000"))+
guides(color=guide_legend('pathway condition'),
size=guide_legend('metabolite counts in each pathway'))+
geom_text(dat,mapping=aes(x=diff.abundance,y=pathway,label=label),
size =2.5,color="grey20",
hjust = 0, nudge_x = 0.05)+
theme_test()+
xlab("Differential Abundance Score")+
ylab(NULL)
#saving
ggsave("outputfile/KEGG_abundancescore3.png", width = 8, height = 4.5)
print(plot.kegg3)
ggsave("outputfile/KEGG_abundancescore3.pdf", width =8, height = 4.5,onefile=F)
print(plot.kegg3)
dev.off()
图中点的大小代表参与每条通路的差异物数量,每条通路的p以及对应数量也用geom_text加到了对应通路旁,如果趋势图从0点向左走,代表该通路中下调差异物多于上调差异物,如果趋势图从0点向右走,代表该通路中上调差异物多于下调差异物,位于0线上的点,代表该通路中上调差异物的数量与下调差异物的数量相等。
期末考试,佛系更新ing, 需要帮助请私
https://mp.weixin.qq.com/s/tc7f7A9rpQlqvrolU5c-SQ