R语言-使用pheatmap函数画热图

1. 构造矩阵

test = matrix(rnorm(200), 20, 10)

test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3

test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2

test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4

colnames(test) = paste("Test", 1:10, sep = "")

rownames(test) = paste("Gene", 1:20, sep = "")

我们按看这个矩阵的四行四列的效果:

2. 构造注释信息

annotation_col = data.frame(

CellType = factor(rep(c("CT1", "CT2"), 5)), Time = 1:5

)

rownames(annotation_col) = paste("Test", 1:10, sep = "")

annotation_row = data.frame(

GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6)))

)

rownames(annotation_row) = paste("Gene", 1:20, sep = "")

注意要为因子的形式!!!

annotation_col的样子:

annotation_row 的样子:

3. 画图

我们使用的是pheatmap包

library(pheatmap)

pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row)

此函数的各种参数:

pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 7, name =

"RdYlBu")))(100), kmeans_k = NA, breaks = NA, border_color = "grey60",

cellwidth = NA, cellheight = NA, scale = "none", cluster_rows = TRUE,

cluster_cols = TRUE, clustering_distance_rows = "euclidean",

clustering_distance_cols = "euclidean", clustering_method = "complete",

clustering_callback = identity2, cutree_rows = NA, cutree_cols = NA,

treeheight_row = ifelse((class(cluster_rows) == "hclust") || cluster_rows,

50, 0), treeheight_col = ifelse((class(cluster_cols) == "hclust") ||

cluster_cols, 50, 0), legend = TRUE, legend_breaks = NA,

legend_labels = NA, annotation_row = NA, annotation_col = NA,

annotation = NA, annotation_colors = NA, annotation_legend = TRUE,

annotation_names_row = TRUE, annotation_names_col = TRUE,

drop_levels = TRUE, show_rownames = T, show_colnames = T, main = NA,

fontsize = 10, fontsize_row = fontsize, fontsize_col = fontsize,

angle_col = c("270", "0", "45", "90", "315"), display_numbers = F,

number_format = "%.2f", number_color = "grey30", fontsize_number = 0.8

* fontsize, gaps_row = NULL, gaps_col = NULL, labels_row = NULL,

labels_col = NULL, filename = NA, width = NA, height = NA,

silent = FALSE, na_col = "#DDDDDD", ...)

相关推荐
Moksha2621 分钟前
5G、VoNR基本概念
开发语言·5g·php
jzlhll12321 分钟前
kotlin Flow first() last()总结
开发语言·前端·kotlin
W.D.小糊涂22 分钟前
gpu服务器安装windows+ubuntu24.04双系统
c语言·开发语言·数据库
用头发抵命43 分钟前
Vue 3 中优雅地集成 Video.js 播放器:从组件封装到功能定制
开发语言·javascript·ecmascript
似水明俊德1 小时前
02-C#.Net-反射-学习笔记
开发语言·笔记·学习·c#·.net
于先生吖1 小时前
Java框架开发短剧漫剧系统:后台管理与接口开发
java·开发语言
khddvbe2 小时前
C++并发编程中的死锁避免
开发语言·c++·算法
wWYy.2 小时前
STL:list
开发语言·c++
TON_G-T3 小时前
day.js和 Moment.js
开发语言·javascript·ecmascript
飞Link3 小时前
具身智能核心架构之 Python 行为树 (py_trees) 深度剖析与实战
开发语言·人工智能·python·架构