ggplot做蝴蝶图

作者: 生信编程日常 | 来源:发表于2020-04-29 23:56 被阅读0次

蝴蝶图是一种形似蝴蝶双向柱状图。做GO term 的时候常常同时展现上调和下调的数据,因此,这里用ggplot2绘制GO term双向柱状图。
输入数据为clusterProfiler的GO term 结果,其他方式做的go term 也可,这里只用到通路和Pvalue。


##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))
image.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')
image.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://mp.weixin.qq.com/s/oqRN52ISl5O24Imj3zwO-g
欢迎关注~

公众号二维码.jpg

相关文章

网友评论

    本文标题:ggplot做蝴蝶图

    本文链接:https://www.haomeiwen.com/subject/jjbowhtx.html