学术资讯 » 学术资源

  • 首 页
  • 期刊选题
  • 期刊点评
  • 期刊大全
  • 学人博客
  • 编辑征稿
  • 投稿选刊
  • 万维群组
  • 学术会议
  • 万维读书
  • SCI/E期刊
  • SSCI期刊
  • AHCI期刊
  • 柱状图|GO、KEGG|标签与柱状图颜色对应

    阅读: 2022/5/9 16:16:33

    原创 TS的美梦 KS科研分享与服务 2022-05-09 10:20

    有小伙伴发来图,想让实现一下,是一个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"))

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

    如有侵权,请联系本站删除!


    浏览(482)
    点赞(0)
    收藏(0)
  • 上一篇:高校10大评审与课题申请书撰写4大要素

    下一篇:谈一谈搜索引擎

  • 首页

  • 文章

  • 期刊

  • 帮助

  • 我的

版权所有 Copyright@2023    备案号:豫ICP备2021036211号