富集通路常用的展示方式就是柱状图,之前我们已经做过很多种了,这里我们展示一种,将通路名称加在柱子上,这样展示的一个好处就是节约地方。
图片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))
往期精彩:
图片
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')
图片
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"))
图片
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"))#设置颜色
往期内容的示例数据和完整代码已经早早躺在群文件里面了,感兴趣的、还没有看过的学习起来。觉得分享有用的点个赞再走呗!
网友评论