• 主页
  • 课程

    关于课程

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

    同等学历教学

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

      关于课程

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

      同等学历教学

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

      未分类

      • 首页
      • 博客
      • 未分类
      • ComplexHeatmap 之 Legends 续(一)

      ComplexHeatmap 之 Legends 续(一)

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

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


      点击上方关注我们




      匆匆又夏天


      2、离散型图例

      离散图例用于离散颜色映射。通过仅提供颜色和中断值,连续颜色映射也可以转换为离散颜色映射。

      可以指定 at 或 labels,但大部分指定标签。颜色应由 legend_gp 指定:

      lgd = Legend(at = 1:6, title = "foo", legend_gp = gpar(fill = 1:6))
      lgd = Legend(labels = month.name[1:6], title = "foo", legend_gp = gpar(fill = 1:6))

      连续颜色映射的离散图例:

      at = seq(0, 1, by = 0.2)
      lgd = Legend(at = at, title = "foo", legend_gp = gpar(fill = col_fun(at)))

      标题位置:

      lgd = Legend(labels = month.name[1:6], title = "foo", legend_gp = gpar(fill = 1:6),
          title_position = "lefttop")
      lgd = Legend(labels = month.name[1:6], title = "foo", legend_gp = gpar(fill = 1:6),
          title_position = "leftcenter-rot")

      大小由 grid_width 和 grid_height 控制:

      lgd = Legend(at = 1:6, legend_gp = gpar(fill = 1:6), title = "foo", 
          grid_height = unit(1, "cm"), grid_width = unit(5, "mm"))

      标签的图形参数由 labels_gp 控制:

      lgd = Legend(labels = month.name[1:6], legend_gp = gpar(fill = 1:6), title = "foo", 
          labels_gp = gpar(col = "red", fontsize = 14))

      标题的图形参数由 title_gp 控制:

      lgd = Legend(labels = month.name[1:6], legend_gp = gpar(fill = 1:6), title = "foo", 
          title_gp = gpar(col = "red", fontsize = 14))

      标题和标签整合 gridtext 包的复杂文本:

      lgd = Legend(
          title = gt_render("<span style='color:orange'>**Legend title**</span>"), 
          title_gp = gpar(box_fill = "grey"),
          at = c(-3, 0, 3), 
          labels = gt_render(c("**negative** three", "*zero*", "**positive** three")),
          legend_gp = gpar(fill = 1:3)
      )

      网格的边界由 border 控制:

      lgd = Legend(labels = month.name[1:6], legend_gp = gpar(fill = 1:6), title = "foo", 
          border = "red")

      离散图例可以将网格排列成多行或/和多列。如果 ncol 设置为数字,则网格将排列为 ncol 列:

      lgd = Legend(labels = month.name[1:10], legend_gp = gpar(fill = 1:10), 
          title = "foo", ncol = 3)

      仍然根据多列图例计算标题位置:

      lgd = Legend(labels = month.name[1:10], legend_gp = gpar(fill = 1:10), title = "foo", 
          ncol = 3, title_position = "topcenter")

      通过设置 by_row = TRUE 来选择按行排列:

      lgd = Legend(labels = month.name[1:10], legend_gp = gpar(fill = 1:10), title = "foo", 
          ncol = 3, by_row = TRUE)

      两列之间的间隙由 gap 或 column_gap 控制。这两个参数的处理方式相同:

      lgd = Legend(labels = month.name[1:10], legend_gp = gpar(fill = 1:10), title = "foo", 
          ncol = 3, gap = unit(1, "cm"))

      行之间的间隙由 row_gap 控制:

      lgd = Legend(labels = month.name[1:10], legend_gp = gpar(fill = 1:10), title = "foo", 
          ncol = 3, row_gap = unit(5, "mm"))

      除了 ncol,还可以通过 nrow 指定布局。请注意,不能同时使用 ncol 和 nrow:

      lgd = Legend(labels = month.name[1:10], legend_gp = gpar(fill = 1:10), 
          title = "foo", nrow = 3)

      一种极端情况是所有级别都 放在一排 并且标题旋转 90 度。图例的高度将是旋转标题的高度:

      lgd = Legend(labels = month.name[1:6], legend_gp = gpar(fill = 1:6), title = "foooooo", 
          nrow = 1, title_position = "lefttop-rot")

      很多人可能会喜欢以下风格:

      lgd = Legend(labels = month.name[1:6], legend_gp = gpar(fill = 1:6), title = "foooooo", 
          nrow = 1, title_position = "leftcenter")

      Legend() 还支持使用简单的图形(例如点、线、箱线图)作为图例。type 参数可以指定为 points 或 p,可以使用数字表示 pch 或单字母表示 pch:

      lgd = Legend(labels = month.name[1:6], title = "foo", type = "points", 
          pch = 1:6, legend_gp = gpar(col = 1:6), background = "#FF8080")
      lgd = Legend(labels = month.name[1:6], title = "foo", type = "points", 
          pch = letters[1:6], legend_gp = gpar(col = 1:6), background = "white")

      或者设置 type = "lines"/type = "l" 使用线条作为图例:

      lgd = Legend(labels = month.name[1:6], title = "foo", type = "lines", 
          legend_gp = gpar(col = 1:6, lty = 1:6), grid_width = unit(1, "cm"))

      或设置 type = "boxplot"/type = "box" 以使用箱线图作为图例:

      lgd = Legend(labels = month.name[1:6], title = "foo", type = "boxplot",
          legend_gp = gpar(fill = 1:6))

      当 pch 为整数时,26:28 中的数字对应以下符号:

      lgd = Legend(labels = paste0("pch = ", 26:28), type = "points", pch = 26:28)

      在上面显示的所有示例中,标签都是单行。还支持多行标签。如以下示例所示,多线标签的图例网格会自动延长:

      lgd = Legend(labels = c("aaaaanaaaaa", "bbbbbnbbbbb", "c", "d"),
          legend_gp = gpar(fill = 1:4))

      如果图例排列成多行或多列,则图例网格的大小将调整为行数最多的标签:

      lgd = Legend(labels = c("aaaaanaaaaa", "c", "d", "bbbbbnbbbbb"),
          legend_gp = gpar(fill = 1:4), nrow = 2)

      最后一个有用的参数图形可用于自定义图例图形。图形的值应该是带有四个参数的函数列表:x 和 y:图例网格的中心,w 和 h:图例网格的宽度和高度。图形的长度应与 at 或标签相同。如果图形是名称与标签相对应的命名列表,则图形列表的顺序会自动调整:

      lgd = Legend(labels = letters[1:4],
          graphics = list(
              function(x, y, w, h) grid.rect(x, y, w*0.33, h, gp = gpar(fill = "red")),
              function(x, y, w, h) grid.rect(x, y, w, h*0.33, gp = gpar(fill = "blue")),
              function(x, y, w, h) grid.text("A", x, y, gp = gpar(col = "darkgreen")),
              function(x, y, w, h) grid.points(x, y, gp = gpar(col = "orange"), pch = 16)
          ))



      未完待续。


      收官!


      代码 我上传到 QQ 群 老俊俊生信交流群 文件夹里。欢迎加入。加我微信我也拉你进 微信群聊 老俊俊生信交流群 哦。

      群二维码:


      老俊俊微信:




      知识星球:



      所以今天你学习了吗?

      欢迎小伙伴留言评论!

      点击我留言!

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

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

      如果觉得对您帮助很大,赏杯快乐水喝喝吧!



       往期回顾 




      ◀ComplexHeatmap 之 Legends

      ◀ComplexHeatmap 之 Heatmap List 续(二)

      ◀ComplexHeatmap 之 Heatmap List 续(一)

      ◀ComplexHeatmap 之 Heatmap List

      ◀ComplexHeatmap 之 Heatmap Annotations 续(三)

      ◀ComplexHeatmap 之 Heatmap Annotations 续(二)

      ◀ComplexHeatmap 之 Heatmap Annotations 续(一)

      ◀ComplexHeatmap 之 Heatmap Annotations

      ◀ComplexHeatmap 之 A Single Heatmap 续(二)

      ◀ComplexHeatmap 之 A Single Heatmap 续(一)


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

      • 分享:
      作者头像
      weinfoadmin

      上一篇文章

      你看过 NCBI 的基因组和注释文件吗?
      2021年9月10日

      下一篇文章

      ComplexHeatmap 之 Legends
      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年
      在线支付 激活码

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