富集通路常用的展示方式就是柱狀圖唠梨,之前我們已經(jīng)做過很多種了碴萧,這里我們展示一種,將通路名稱加在柱子上显蝌,這樣展示的一個好處就是節(jié)約地方预伺。
圖片
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))
往期精彩:
復(fù)現(xiàn)Cell圖表:雙側(cè)柱狀圖展示上下調(diào)GO富集結(jié)果
圖片
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|標(biāo)簽與柱狀圖顏色對應(yīng)
圖片
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"))
轉(zhuǎn)錄組不求人系列(十三): 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"))#設(shè)置顏色
往期內(nèi)容的示例數(shù)據(jù)和完整代碼已經(jīng)早早躺在群文件里面了酬诀,感興趣的、還沒有看過的學(xué)習(xí)起來骆撇。覺得分享有用的點個贊再走唄瞒御!