蝴蝶图是一种形似蝴蝶双向柱状图。做GO term 的时候常常同时展现上调和下调的数据,因此,这里用ggplot2绘制GO term双向柱状图。
输入数据为clusterProfiler的GO term 结果,其他方式做的go term 也可,这里只用到通路和Pvalue。
![](https://img.haomeiwen.com/i20297934/1cf7e1b13153cbdf.png)
##ggplot2 作图
library(ggplot2)
library(stringr)
#up
updata<-goBP.up@result[1:5,c("Description","pvalue")]
updata<-updata[order(updata$pvalue,decreasing = T),]
updata$Description<-factor(updata$Description,levels = updata$Description)
#上调 GO
GO_up <- ggplot(updata, aes(Description, -log(pvalue,10))) +
geom_col(fill = 'orange', color = 'black', width = 0.6) +
theme(panel.grid = element_blank(), panel.background = element_rect(fill = 'transparent')) +
theme(axis.line.x = element_line(colour = 'black'), axis.line.y = element_line(colour = 'transparent'), axis.ticks.y = element_line(colour = 'transparent')) +
theme(plot.title = element_text(hjust = 0.5, face = 'plain')) +
coord_flip() +
geom_hline(yintercept = 0) +
labs(x = '', y = '', title = 'UP')+scale_x_discrete(labels=function(x) str_wrap(x, width=50))
![](https://img.haomeiwen.com/i20297934/4f573963d2b7927c.png)
#down
downdata<-goBP.down@result[1:5,c("Description","pvalue")]
downdata<-downdata[order(downdata$pvalue,decreasing = T),]
downdata$Description<-factor(downdata$Description,levels = downdata$Description)
term.down<- levels(downdata$Description)
#下调 GO
GO_down <- ggplot(downdata, aes(Description, -log(pvalue,10))) +
geom_col(fill = 'green4', color = 'black', width = 0.6) +
theme(panel.grid = element_blank(), panel.background = element_rect(fill = 'transparent')) +
theme(axis.line.x = element_line(colour = 'black'), axis.line.y = element_line(colour = 'transparent'), axis.ticks.y = element_line(colour = 'transparent')) +
theme(plot.title = element_text(hjust = 0.5, face = 'plain')) +
geom_hline(yintercept = 0) +
coord_flip() +labs(x = '', y = '', title = 'DOWN') +scale_x_discrete(labels = term.down, position = 'top')
![](https://img.haomeiwen.com/i20297934/4cc0b22816b24b88.png)
#合并
library(cowplot)
plot_grid(GO_up, GO_down, nrow = 2, ncol = 2, rel_heights = c(9, 1), labels = 'GO term -log10(p-value)', label_x = 0.5, label_y = 0, label_fontface = 'plain')
![](https://img.haomeiwen.com/i20297934/9ff554a51fe6436c.png)
参考:https://mp.weixin.qq.com/s/oqRN52ISl5O24Imj3zwO-g
欢迎关注~
![](https://img.haomeiwen.com/i20297934/3bdb6f15702ffa36.jpg)
网友评论