R包:ggheatmapper热图

news/2024/10/3 20:00:35/

在这里插入图片描述

加载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.ppmy.cn/news/1533520.html

相关文章

【Linux】解锁磁盘文件奥秘,高效数据管理的实战技巧

磁盘文件 1. 引言2. 磁盘的机械构成3. 磁盘的物理存储3.1. CHS定位寻址法 4. 磁盘的逻辑存储4.1. LBA地址4.2. inode4.3. 分区、分组4.4. Boot Block4.5. 块组 — Block group4.5.1. inode Table4.5.2. Data Blocks4.5.3. inode Bitmap4.5.4. Block Bitmap4.5.5. GDT4.5.6. Sup…

Ref-NeuS参数记录

前言 这篇文章中的uncertainty估计非常值得参考&#xff0c;尤其是寻找当前view到其他view的投影点&#xff0c;这里记录一下这部分代码的参数&#xff0c;因为它起名实在太混乱了&#xff01;&#xff01; code 假设有一共有36个view&#xff0c;每次取4096条光线&#xff…

执行力怎么培养?

执行力怎么培养&#xff1f; 并行&#xff1a;适合在初期养成习惯&#xff0c;不抱对结果的期望天才就是强迫症&#xff1a;适合中期修身&#xff1a;适合高级 并行&#xff1a;适合在初期养成习惯&#xff0c;不抱对结果的期望 在你开始做任何事情的时候&#xff0c;不要一开…

Threejs绘制圆锥体

上一章节实现了胶囊体的绘制&#xff0c;这节来绘制圆锥体&#xff0c;圆锥体就是三角形旋转获得的&#xff0c;如上文一样&#xff0c;先要创建出基础的组件&#xff0c;包括场景&#xff0c;相机&#xff0c;灯光&#xff0c;渲染器。代码如下&#xff1a; initScene() {this…

【深海王国】初中生也能画的电路板?目录合集

Hi٩(๑ ^ o ^ ๑)۶, 各位深海王国的同志们&#xff0c;早上下午晚上凌晨好呀~辛勤工作的你今天也辛苦啦 (o゜▽゜)o☆ 今天大都督为大家带来系列文章《初中生也能画的电路板》&#xff0c;帮你一周内快速入门PCB设计&#xff0c;手把手教你从元器件库添加、电路原理图绘制、…

宠物空气净化器希喂和352哪个好用?两大爆火机型哪款吸毛、除臭效果比较好?

猫毛、狗毛、鹦鹉毛&#xff0c;总之只要家里养着有带毛的宠物&#xff0c;毛就会出现在各种地方&#xff0c;床上、沙发上、衣服上、水杯里...根本躲不开。而且&#xff0c;除了肉眼可见的&#xff0c;呼吸时、说话时&#xff0c;不经意间还会吃到毛毛。这些毛毛飘在空气里时&…

什么是原生IP?

代理IP的各个类型称呼有很多&#xff0c;且它们在网络使用和隐私保护方面扮演着不同的角色。今天将探讨什么是原生IP以及原生IP和住宅IP之间的区别&#xff0c;帮助大家更好地理解这两者的概念和实际应用&#xff0c;并选择适合自己的IP类型。 一、什么是原生IP&#xff1f; 原…

音视频入门基础:FLV专题(10)——Script Tag实例分析

一、引言 在《音视频入门基础&#xff1a;FLV专题&#xff08;9&#xff09;——Script Tag简介》中对FLV文件的Script Tag进行了简介。下面用一个具体的例子来对Script Tag进行分析。 二、Script Tag的Tag header实例分析 用notepad打开《音视频入门基础&#xff1a;FLV专题…