R 热图绘制heatmap②

简介: 使用pheatmap包绘制热图一般而言,pheatmap较heatmap.2等更为简洁以及易于理解,对于初学者而言是一款不错的热图绘制软件。rm(list=ls())setwd("E:\\Rwork")library(pheatmap) ...

使用pheatmap包绘制热图

  • 一般而言,pheatmap较heatmap.2等更为简洁以及易于理解,对于初学者而言是一款不错的热图绘制软件。
rm(list=ls())

setwd("E:\\Rwork")
library(pheatmap)  
#创建数据集test测试矩阵  
test = matrix(rnorm(400), 20, 20)  
colnames(test) <- paste("sample",1:20,sep = "")
rownames(test)   <- paste("gene", 1:20,sep = "")
test[1:10, seq(1, 20, 2)] = test[1:10, seq(1, 20, 2)] + 5 
test[11:20, seq(2, 20, 2)] = test[11:20, seq(2, 20, 2)] - 5 
pheatmap(test)  
img_f5dc2c73376bf75a5c5f1feff0c8e9ed.png
  • cluster_row = FALSE, cluster_col = FALSE
  • treeheight_row=0, treeheight_col=0
  
# 在热图格子里展示文本  
pheatmap(test, display_numbers = TRUE)  
pheatmap(test, display_numbers = TRUE, 
         number_format = "%.1e")  

img_06ade067139bbbb0abeb07a05e78786a.png

cluster_row = FALSE, cluster_col = FALSE是否聚类,#可设置参数display_numbers将数值显示在热图的格子中,可通过number_format设置数值的格式,较常用的有".2f"(保留小数点后两位),".1e"(科学计数法显示,保留小数点后一位),number_color设置显示内容的颜色:
pheatmap(test, display_numbers = TRUE, number_format = "%.2f", number_color="purple") #"%.2f"表示保留小数点后两位


#pheatmap还可以显示行或列的分组信息,支持多种分组;  
annotation_col = data.frame(sampleType = factor(rep(c("contol", "knockdown"),10)),
                            sampleclass = factor(rep(c("normal", "tumor"),10)),
                            samplecluster = factor(rep(c("invasive", "noninvasive"),10))) 
rownames(annotation_col) <- colnames(test)






annotation_row = data.frame(geneType = factor(rep(c("kegg1", "kegg2"),10)),
                           geneclass = factor(rep(c("go1", "go2"),10))
                          ) 
rownames(annotation_row) <- rownames(test)

pheatmap(test, annotation_col = annotation_col, 
         annotation_row = annotation_row,
         treeheight_row=0, treeheight_col=0,
         cutree_rows=3,cutree_cols=2) 

img_bc8292e42f9b74c2058057e80b9396cb.png

#pheatmap还能够根据特定的条件将热图分隔开;
# cutree_rows, cutree_cols:根据行列的聚类数将热图分隔开;
pheatmap(test,cutree_rows=2,cutree_cols=2)

img_1a524556d87b53627d86da17afab707d.png

#还可以自己设定各个分组的颜色  
ann_colors = list(sampleType = c(contol = "grey", knockdown = "black"), #连续数值型分组可设置成渐变  
                  sampleclass = c(normal = "#1B9E77", tumor= "#D95F02"))  
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row,  
         annotation_colors = ann_colors)  

img_f34dee2f5c9e2fbbdbb93433a4c02cb8.png
目录
相关文章
|
6月前
|
数据可视化 数据挖掘 数据处理
R绘图 | 浅谈散点图及其变体的作图逻辑
R绘图 | 浅谈散点图及其变体的作图逻辑
96 0
|
6天前
|
数据可视化
绘制GGPLOT2双色XY区间面积图组合交叉折线图数据可视化
绘制GGPLOT2双色XY区间面积图组合交叉折线图数据可视化
|
3月前
|
数据可视化 Python
使用pygal库绘制直方图、XY线图和饼状图的技术指南
使用pygal库绘制直方图、XY线图和饼状图的技术指南
20 0
|
8月前
|
Go
如何用ggplot2绘制基因功能富集气泡图?
如何用ggplot2绘制基因功能富集气泡图?
|
10月前
|
人工智能 数据可视化
跟SCI学umap图| ggplot2 绘制umap图,坐标位置 ,颜色 ,大小还不是你说了算
跟SCI学umap图| ggplot2 绘制umap图,坐标位置 ,颜色 ,大小还不是你说了算
711 1
|
10月前
|
数据可视化 数据挖掘 数据处理
ComplexHeatmap|绘制单个热图-I
ComplexHeatmap|绘制单个热图-I
144 0
|
10月前
|
算法
ggplot2|从0开始绘制PCA图
ggplot2|从0开始绘制PCA图
291 0
|
10月前
|
数据挖掘
ggplot2| 绘制KEGG气泡图
ggplot2| 绘制KEGG气泡图
194 0
|
11月前
|
机器学习/深度学习 算法 数据可视化
R绘图案例|基于分面的面积图绘制
R绘图案例|基于分面的面积图绘制
10830 0
|
11月前
基于 ggdensity 包的等高线绘制
基于 ggdensity 包的等高线绘制
77 0

热门文章

最新文章