打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
柱状图|GO、KEGG|标签与柱状图颜色对应
userphoto

2022.05.09 重庆

关注

有小伙伴发来图,想让实现一下,是一个KEGG分析的柱状图,图的特点是文字标签颜色与柱子颜色一样,其实这个图也就这么一个特点,其他的柱状图的特征都没有什么,很普通的ggplot做法,最终效果如下:

首先读入数据,示例数据使用的是之前的文章:复现《nature communications》图表(四):ggplot画多组富集气泡图

setwd("E:/")A <- read.csv("GO.csv", header = T)library(ggplot2)library(forcats)A$Description <- as.factor(A$Description)A$Description <- fct_inorder(A$Description)

先做一个普通的柱状图。只需要两个参数,一个是gene count,一个是富集的GO或者KEGG terms。

ggplot(A)+  geom_bar(aes(Description, Count),stat = "identity")+  coord_flip()

我们先不急着实现文字标签,先进行ggplot基础的修饰。

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))

接下来就是最后一步了,将文字标签颜色设置为和柱子一样就完成了。我这里是分为了3组,将三组标签赋予对应的颜色即可。

table(A$Cluster)#Cluster1 Cluster2 Cluster3 #13       12       13 col <- c(rep("#852f88",13),rep("#eb990c",12),rep("#0f8096",13))
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"))

还不错,其他的细节问题这里就不再赘述了,自行调整吧!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
敲击几行pathway代码,轻松绘制富集气泡图
跟SCI学umap图| ggplot2 绘制umap图,坐标位置 ,颜色 ,大小还不是你说了算
绘制分组柱形图的各种样式
高度定制的go和kegg富集分析R语言绘图 | Circular barplot
干货|高逼格的sci图片手把手教学
气泡图成猫啦!变身之术拿捏!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服