• 主页
  • 课程

    关于课程

    • 课程归档
    • 成为一名讲师
    • 讲师信息
    同等学历教学

    同等学历教学

    免费
    阅读更多
  • 特色
    • 展示
    • 关于我们
    • 问答
  • 事件
  • 个性化
  • 博客
  • 联系
  • 站点资源
    有任何问题吗?
    (00) 123 456 789
    weinfoadmin@weinformatics.cn
    注册登录
    恒诺新知
    • 主页
    • 课程

      关于课程

      • 课程归档
      • 成为一名讲师
      • 讲师信息
      同等学历教学

      同等学历教学

      免费
      阅读更多
    • 特色
      • 展示
      • 关于我们
      • 问答
    • 事件
    • 个性化
    • 博客
    • 联系
    • 站点资源

      未分类

      • 首页
      • 博客
      • 未分类
      • circlize 之 Legends

      circlize 之 Legends

      • 发布者 weinfoadmin
      • 分类 未分类, 老俊俊的生信笔记
      • 日期 2021年9月10日
      • 评论 0评论

      感谢老俊俊的大力支持。我们会每日跟新,欢迎您关注老俊俊的生信笔记。

      circlize 之 Legends

      circlize 包自身绘图时不能生成图例,可以借助其它 R 包来绘制图例,首先绘制一个环形图:

      library(circlize)

      col_fun = colorRamp2(c(-2, 0, 2), c("green", "yellow", "red"))
      circlize_plot = function() {
          set.seed(12345)
          sectors = letters[1:10]
          circos.initialize(sectors, xlim = c(0, 1))
          circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
              circos.points(runif(20), runif(20), cex = 0.5, pch = 16, col = 2)
              circos.points(runif(20), runif(20), cex = 0.5, pch = 16, col = 3)
          })
          circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
              circos.lines(sort(runif(20)), runif(20), col = 4)
              circos.lines(sort(runif(20)), runif(20), col = 5)
          })

          for(i in 1:10) {
              circos.link(sample(sectors, 1), sort(runif(10))[1:2],
                          sample(sectors, 1), sort(runif(10))[1:2],
                          col = add_transparency(col_fun(rnorm(1))))
          }
          circos.clear()
      }

      使用 ComplexHeatmap 包的 Legend()函数来创建图例,使用 packLegend()函数打包图例:

      library(ComplexHeatmap)
      # discrete 离散型图例
      lgd_points = Legend(at = c("label1", "label2"), type = "points",
          legend_gp = gpar(col = 2:3), title_position = "topleft",
          title = "Track1")
      # discrete 离散型图例
      lgd_lines = Legend(at = c("label3", "label4"), type = "lines",
          legend_gp = gpar(col = 4:5, lwd = 2), title_position = "topleft",
          title = "Track2")
      # continuous 连续型图例
      lgd_links = Legend(at = c(-2, -1, 0, 1, 2), col_fun = col_fun,
          title_position = "topleft", title = "Links")

      # 打包图例
      lgd_list_vertical = packLegend(lgd_points, lgd_lines, lgd_links)
      lgd_list_vertical

      画图:

      circlize_plot()
      # next the grid graphics are added directly to the plot
      # where circlize has created.
      draw(lgd_list_vertical, x = unit(4, "mm"), y = unit(4, "mm"), just = c("left", "bottom"))

      将图例放置在不同位置:

      lgd_list_vertical2 = packLegend(lgd_points, lgd_lines)
      circlize_plot()
      # next the grid graphics are added directly to the plot
      # where circlize has created.
      draw(lgd_list_vertical2, x = unit(4, "mm"), y = unit(4, "mm"), just = c("left", "bottom"))
      draw(lgd_links, x = unit(1, "npc") - unit(2, "mm"), y = unit(4, "mm"),
          just = c("right", "bottom"))

      使用 gridBase 包添加图例:

      library(gridBase)
      plot.new()
      circle_size = unit(1, "snpc") # snpc unit gives you a square region

      pushViewport(viewport(x = 0, y = 0.5, width = circle_size, height = circle_size,
          just = c("left", "center")))
      par(omi = gridOMI(), new = TRUE)
      circlize_plot()
      upViewport()

      draw(lgd_list_vertical, x = circle_size, just = "left")

      将图例水平放置:

      lgd_points = Legend(at = c("label1", "label2"), type = "points",
          legend_gp = gpar(col = 2:3), title_position = "topleft",
          title = "Track1", nrow = 1)

      lgd_lines = Legend(at = c("label3", "label4"), type = "lines",
          legend_gp = gpar(col = 4:5, lwd = 2), title_position = "topleft",
          title = "Track2", nrow = 1)

      lgd_links = Legend(at = c(-2, -1, 0, 1, 2), col_fun = col_fun,
          title_position = "topleft", title = "Links", direction = "horizontal")

      lgd_list_horizontal = packLegend(lgd_points, lgd_lines, lgd_links,
          direction = "horizontal")

      # 添加图例
      plot.new()
      pushViewport(viewport(x = 0.5, y = 1, width = circle_size, height = circle_size,
          just = c("center", "top")))
      par(omi = gridOMI(), new = TRUE)
      circlize_plot()
      upViewport()

      draw(lgd_list_horizontal, y = unit(1, "npc") - circle_size, just = "top")

      欢迎小伙伴留言评论!

      点击我留言!

      今天的分享就到这里了,敬请期待下一篇!

      最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!

      如果觉得对您帮助很大,打赏一下吧!

      请关注“恒诺新知”微信公众号,感谢“R语言“,”数据那些事儿“,”老俊俊的生信笔记“,”冷🈚️思“,“珞珈R”,“生信星球”的支持!

      • 分享:
      作者头像
      weinfoadmin

      上一篇文章

      QPCRpro 正式上线!
      2021年9月10日

      下一篇文章

      QPCR数据添加 p 值和显著性一次解决!
      2021年9月10日

      你可能也喜欢

      2-1675088548
      lncRNA和miRNA生信分析系列讲座免费视频课和课件资源包,干货满满
      30 1月, 2023
      9-1675131201
      如何快速批量修改 Git 提交记录中的用户信息
      26 1月, 2023
      8-1678501786
      肿瘤细胞通过改变CD8+ T细胞中的丙酮酸利用和琥珀酸信号来调控抗肿瘤免疫应答。
      7 12月, 2022

      留言 取消回复

      要发表评论,您必须先登录。

      搜索

      分类

      • R语言
      • TCGA数据挖掘
      • 单细胞RNA-seq测序
      • 在线会议直播预告与回放
      • 数据分析那些事儿分类
      • 未分类
      • 生信星球
      • 老俊俊的生信笔记

      投稿培训

      免费

      alphafold2培训

      免费

      群晖配置培训

      免费

      最新博文

      Nature | 单细胞技术揭示衰老细胞与肌肉再生
      301月2023
      lncRNA和miRNA生信分析系列讲座免费视频课和课件资源包,干货满满
      301月2023
      如何快速批量修改 Git 提交记录中的用户信息
      261月2023
      logo-eduma-the-best-lms-wordpress-theme

      (00) 123 456 789

      weinfoadmin@weinformatics.cn

      恒诺新知

      • 关于我们
      • 博客
      • 联系
      • 成为一名讲师

      链接

      • 课程
      • 事件
      • 展示
      • 问答

      支持

      • 文档
      • 论坛
      • 语言包
      • 发行状态

      推荐

      • iHub汉语代码托管
      • iLAB耗材管理
      • WooCommerce
      • 丁香园论坛

      weinformatics 即 恒诺新知。ICP备案号:粤ICP备19129767号

      • 关于我们
      • 博客
      • 联系
      • 成为一名讲师

      要成为一名讲师吗?

      加入数以千计的演讲者获得100%课时费!

      现在开始

      用你的站点账户登录

      忘记密码?

      还不是会员? 现在注册

      注册新帐户

      已经拥有注册账户? 现在登录

      close
      会员购买 你还没有登录,请先登录
      • ¥99 VIP-1个月
      • ¥199 VIP-半年
      • ¥299 VIP-1年
      在线支付 激活码

      立即支付
      支付宝
      微信支付
      请使用 支付宝 或 微信 扫码支付
      登录
      注册|忘记密码?