当前位置: 首页 > article >正文

R包:ggheatmapper热图

在这里插入图片描述

加载R包

# devtools::install_github("csgroen/ggheatmapper")

library(tidyverse)
library(patchwork)
library(ggheatmapper)

数据

data(tcgaBLCA_ex)
gexp <- tcgaBLCA_ex$gexp

图1

gghm <- ggheatmap(gexp,
          hm_colors = 'RdBu',
          hm_color_values = scales::rescale(c(-4,-2,-1,-0.5,-0.25,0,0.25,0.5,1,2,4,6)),
          scale = TRUE,
          center = TRUE,
          show_dend_row = TRUE,
          colors_title = "Scaled expression (log2 UQ)",
          show_colnames = FALSE)

gghm

在这里插入图片描述

图2

gghm &
  theme(axis.text = element_text(size = 6))

在这里插入图片描述

图3

sample_annot <- tcgaBLCA_ex$sample_annot %>% as_tibble()
genes <- rownames(gexp)
tcgaBLCA_tb <- gexp %>%
  t() %>%
  as.data.frame() %>%
  rownames_to_column("sample") %>%
  left_join(sample_annot, by = "sample") %>%
  tibble() %>%
  group_by(consensusClass)

gr_gghm <- ggheatmap(tcgaBLCA_tb,
    colv = "sample",
    rowv = genes,
    hm_colors = 'RdBu',
    hm_color_values = scales::rescale(c(-4,-2,-1,-0.5,-0.25,0,0.25,0.5,1,2,4,6)),
    scale = TRUE,
    center = TRUE,
    show_dend_row = FALSE,
    show_colnames = FALSE,
    show_rownames = FALSE,
    group_colors = c(`Ba/Sq` = "#fe4a49", LumNS = "#32837d", LumP = "#06d6a0", LumU = "#009fb7",
                     `Stroma-rich` = "#f9c80e", `NE-like` = "#7d5ba6"),
    colors_title = "Scaled expression (log2 UQ)")

gr_gghm +
  plot_layout(guides = 'collect')

在这里插入图片描述

图4

get_data(gr_gghm) %>% colnames()

gr_gghm <- add_tracks(gr_gghm,
           track_columns = c("stage", "node", "metastasis"),
           track_colors = list(stage = 'Greys', node = 'Oranges', metastasis = 'Reds'),
           track_prop = 0.2)
#> Adding missing grouping variables: `consensusClass`
gr_gghm +
  plot_layout(guides = 'collect')

在这里插入图片描述

图5

  • 图1
tcgaBLCA_tb2 <- get_data(gr_gghm)
plt_corlines <- tcgaBLCA_tb2 %>%
  ungroup() %>%
  select(observations, LumP:NE.like) %>%
  pivot_longer(cols = -observations, names_to = "subtype", values_to = "cor") %>%
  ggplot(aes(observations, cor, color = subtype, group = subtype)) +
  geom_line() +
  scale_y_continuous(position = "right") +
  scale_color_manual(values = c(`Ba.Sq` = "#fe4a49", LumNS = "#32837d", LumP = "#06d6a0", LumU = "#009fb7",
                                `Stroma.rich` = "#f9c80e", `NE.like` = "#7d5ba6")) +
  guides(color = FALSE) +
  labs(y = "Correlation\n to centroid") +
  theme_quant()

plt_corlines

在这里插入图片描述

  • 图2
plt_row_annot <- tcgaBLCA_ex$gene_annot %>%
  mutate(gene_symbol = factor(gene_symbol, levels = get_rowLevels(gr_gghm)),
         group = 'signature') %>%
  ggplot(aes(gene_symbol, group, fill = signature)) +
  geom_tile() +
  labs(y = "") +
  coord_flip() +
  theme_sparse2()
plt_row_annot

在这里插入图片描述

  • 图3
gghm_complete <- gr_gghm %>%
  align_to_hm(plt_corlines, newplt_size_prop = 0.3) %>%
  align_to_hm(plt_row_annot, pos = "left", newplt_size_prop = 0.08, 
              legend_action = "collect", tag_level = 'keep')
gghm_complete

在这里插入图片描述

  • 图4
gghm_complete <- gghm_complete &
  theme(legend.text = element_text(size = 7),
        legend.title = element_text(size = 8))
gghm_complete

在这里插入图片描述

  • 图5
plt_subtype_count <- ggplot(sample_annot, aes(consensusClass, fill = consensusClass)) +
  geom_bar() +
  scale_fill_manual(values = c(`Ba/Sq` = "#fe4a49", LumNS = "#32837d", 
                               LumP = "#06d6a0", LumU = "#009fb7",
                                `Stroma-rich` = "#f9c80e", 
                               `NE-like` = "#7d5ba6")) +
  labs(y = 'Number of samples') +
  guides(fill = FALSE) +
  theme_quant() +
  theme(axis.ticks.x = element_line(color = "black"),
        axis.text.x = element_text(color = "black", angle = 45, hjust = 1, vjust = 1))

plt_subtype_count

在这里插入图片描述

  • 图6
library(patchwork)
new_col <- (plt_subtype_count + plot_spacer()) +
  plot_layout(heights = c(0.3,0.7))

(new_col | gghm_complete) +
  plot_layout(widths = c(0.4,0.6))

在这里插入图片描述

图6

sig_list <- split(tcgaBLCA_ex$gene_annot$gene_symbol, tcgaBLCA_ex$gene_annot$signature)

gr_gghm <- ggheatmap(tcgaBLCA_tb,
    colv = "sample",
    rowv = sig_list,
    hm_colors = 'RdBu',
    hm_color_values = scales::rescale(c(-4,-2,-1,-0.5,-0.25,0,0.25,0.5,1,2,4,6)),
    scale = TRUE,
    center = TRUE,
    show_dend_row = FALSE,
    show_colnames = FALSE,
    show_rownames = FALSE,
    group_colors = c(`Ba/Sq` = "#fe4a49", LumNS = "#32837d", LumP = "#06d6a0", LumU = "#009fb7",
                     `Stroma-rich` = "#f9c80e", `NE-like` = "#7d5ba6"),
    colors_title = "Scaled expression (log2 UQ)")

gr_gghm +
  plot_layout(guides = 'collect')

在这里插入图片描述

参考

  • https://csgroen.github.io/ggheatmapper/articles/ggheatmapper.html

http://www.kler.cn/news/328924.html

相关文章:

  • Postgresql源码(136)syscache/relcache 缓存及失效机制
  • 【数据结构】环形队列(循环队列)学习笔记总结
  • 技术人生-电脑突然卡顿怎么办
  • 滚雪球学Oracle[3.4讲]:事务控制与锁管理
  • Vite:为什么选 Vite
  • 22.4k star,好用、强大的链路监控软件,skywalking
  • gcc选项-fno-access-control 使用
  • redis中的数据类型(Set与ZSet)
  • pre-commit 的配置文件
  • c++primier第十二章类和动态内存
  • Flink 性能优化的高频面试题及答案
  • 【redis-03】redis缓存穿透、缓存击穿、缓存雪崩
  • 平安养老险深圳分公司积极开展“金融教育宣传月”活动,展现金融为民新风尚
  • C++随心记
  • Linux 再入门整理:详解 /etc/fstab 文件
  • diffusion vs GAN
  • HealChat心理大语言模型 丨OPENAIGC开发者大赛高校组AI创作力奖
  • 数据结构-3.7.双端队列
  • 栈(模板)、队列(模板)(9.27)
  • 5分钟精通Excel在go中的使用
  • 7--苍穹外卖-SpringBoot项目中套餐管理 详解(一)
  • QT中的按钮控件和comboBox控件和spinBox控件无法点击的bug
  • 发布-订阅模式演示示例
  • 神点SAAS云财务系统/多账套/前后端全开源
  • 【PostgreSQL】入门篇——索引:提高查询性能的利器
  • 【英特尔IA-32架构软件开发者开发手册第3卷:系统编程指南】2001年版翻译,1-1
  • 论React Native 和 UniApp 的区别
  • 【CTF Web】Pikachu 反射型xss(get) Writeup(反射型XSS+GET请求)
  • 代码随想录Day 59|图论Part09,dijkstra(堆优化版)精讲、Bellman_ford算法精讲
  • 继承实现单例模式的探索(一)