欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > R包:ggheatmapper热图

R包:ggheatmapper热图

2024/10/25 10:23:04 来源:https://blog.csdn.net/H20230717/article/details/142538994  浏览:    关键词: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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com