效果图
数据准备
表达矩阵:data
行为基因,列为样本
分组数据:annotation_col
代码
library(pheatmap)#加载R包
pheatmap(data,scale ="row") #scale行归一化
#添加分组,并上色
rownames(annotation_col) = colnames(data)
ann_colors = list(group = c(Sepsis = "#9EC1D4", Normal = "#E87651"))
pheatmap(data,scale ="row" ,
annotation_col = annotation_col,annotation_colors = ann_colors)
dev.off()
# 选择data的前20行
data_subset <- data[1:40, ]
# 使用pheatmap绘制热图,但只使用data_subset
pheatmap(data_subset,
scale = "row", # 行归一化
cluster_rows = TRUE, cluster_cols = FALSE, # 行聚类,列不进行聚类
clustering_method = "complete", # 聚类的方法
display_numbers = FALSE, number_color = "purple", number_format = "%.2f", # 是否显示每个单元格数值,数字形式
cellwidth = 5, cellheight = 8, # 设置单元格的长、宽
annotation_col = annotation_col, annotation_colors = ann_colors, # 样本标记
border_color = "white", # 样本边框颜色
fontsize = 6, # 设置字体大小
show_rownames = TRUE, show_colnames = TRUE # 是否显示行名和列名
)
dev.off()