富集分析柱状图大集合:通路展示在柱子上

富集通路常用的展示方式就是柱状图,之前我们已经做过很多种了,这里我们展示一种,将通路名称加在柱子上,这样展示的一个好处就是节约地方。

setwd("D:/KS项目/公众号文章/富集柱状图文字添加到柱子上")
library(ggplot2)
df <- read.csv("enrich.csv", header = T)
df$LogP <- -df$LogP

df$labelx=rep(0,nrow(df))
df$labely=seq(nrow(df),1)

ggplot(data = df, 
       aes(LogP, reorder(Description,LogP))) +
  geom_bar(stat="identity",
           alpha=0.5,
           fill="#FE8D3C",
           width = 0.8) + 
  geom_text(aes(x=labelx,
                y=labely,
                label = Description),
            size=3.5, 
            hjust =0)+
  theme_classic()+
  theme(axis.text.y = element_blank(),
        axis.line.y = element_blank(),
        axis.title.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.line.x = element_line(colour = 'black', linewidth = 1),
        axis.text.x = element_text(colour = 'black', size = 10),
        axis.ticks.x = element_line(colour = 'black', linewidth = 1),
        axis.title.x = element_text(colour = 'black', size = 12))+
  xlab("-log10(qvalue)")+
  ggtitle("Enrichment")+
  scale_x_continuous(expand = c(0,0))

往期精彩:

复现Cell图表:双侧柱状图展示上下调GO富集结果


ggplot(A,aes(reorder(Description, ratio),ratio,fill=group))+
  geom_col()+
  theme_bw()+
  theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.border = element_blank(),
        legend.title = element_blank(),
        axis.text = element_text(color="black",size=10),
        axis.line.x = element_line(color='black'),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        legend.position = 'none')+
  coord_flip()+
  geom_segment(aes(y=0, yend=0,x=0,xend=18.5))+
  geom_text(data = A[which(A$ratio>0),],aes(x=Description, y=-0.01, label=Description),
            hjust=1, size=4)+
  geom_text(data = A[which(A$ratio<0),],aes(x=Description, y=0.01, label=Description),
            hjust=0, size=4)+
  geom_text(data = A[which(A$ratio>0),],aes(label=Padj),
            hjust=-0.1, size=4, color='red')+
  geom_text(data = A[which(A$ratio<0),],aes(label=Padj),
            hjust=1.1, size=4, color="red")+
  scale_fill_manual(values = c("#1084A4",
                               "#8D4873"))+
  scale_x_discrete(expand = expansion(mult = c(0,0)))+
  ylim(-0.5, 0.5)+
  labs(x='', y='Ratio')

柱状图|GO、KEGG|标签与柱状图颜色对应


ggplot(A,aes(Description, Count))+
  geom_bar(aes(fill=Cluster),stat = "identity")+
  geom_text(aes(label=Count, y=Count+5),size=3)+
  coord_flip()+
  labs(x='',y='Gene count', title = 'GO enrichment of cluster')+
  scale_fill_manual(values = c('#852f88',
                               '#eb990c',
                               '#0f8096'))+
  theme_bw()+
  theme(panel.grid = element_blank(),
        legend.position = 'none',
        axis.ticks.y = element_blank(),
        plot.title = element_text(hjust = 0.5, size = 10),
        axis.text.y = element_text(size=rel(0.85),colour =col),
        plot.margin=unit(x=c(top.mar=0.2,right.mar=0.2,
                             bottom.mar=0.2,left.mar=0.2),
                         units="inches"))

转录组不求人系列(十三): GO、KEGG富集个性化作图

ggplot(A, aes(x = reorder(Description,Log.q.value.), Log.q.value.,fill=group)) + 
  geom_bar(stat = 'identity',alpha = 0.7) + 
  coord_flip() + 
  theme_bw() + #去除背景色
  theme(panel.grid =element_blank())+
  theme(panel.border = element_rect(size = 0.6))+
  labs(x = "",
       y="Log.q.value.")+
  scale_fill_manual(values = c("#008020","#08519C"))#设置颜色

往期内容的示例数据和完整代码已经早早躺在群文件里面了,感兴趣的、还没有看过的学习起来。觉得分享有用的点个赞再走呗!

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值