![eb83c7f9e4acba07796c1b92873281f9.png](https://img-blog.csdnimg.cn/img_convert/eb83c7f9e4acba07796c1b92873281f9.png)
# Create test matrix
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 = "")
head(test[,1:6])
## Test1 Test2 Test3 Test4 Test5 Test6
## Gene1 3.794921 0.6708733 2.704269 -1.343588842 3.866710 -0.8411551
## Gene2 3.413836 -0.4212030 1.640834 0.188695288 3.230696 -0.2089067
## Gene3 3.395525 1.9352418 5.122096 -1.970689816 3.575553 0.2646297
## Gene4 3.660099 -0.7499712 3.175301 -0.122506409 2.816723 -1.6189546
## Gene5 1.165753 0.2415800 2.842189 1.045472250 3.449153 0.4814919
## Gene6 2.307023 -0.3140961 1.062880 -0.007899432 3.775166 -0.3733476
# Draw heatmaps
library(pheatmap)
## Warning: package 'pheatmap' was built under R version 3.4.4
pheatmap(test)
![0eaf71a6b35450301ff36e5b9ddc429f.png](https://img-blog.csdnimg.cn/img_convert/0eaf71a6b35450301ff36e5b9ddc429f.png)
# scale = "row"参数对行进行归一化
# clustering_method参数设定不同聚类方法,默认为"complete",可以设定为'ward', 'ward.D', 'ward.D2', 'single', 'complete', 'average', 'mcquitty', 'median' or 'centroid'
pheatmap(test,scale = "row", clustering_method = "average")
![e023a8b040a22038251785c531194bd6.png](https://img-blog.csdnimg.cn/img_convert/e023a8b040a22038251785c531194bd6.png)
#表示行聚类使用皮尔森相关系数聚类,默认为欧氏距离"euclidean"
pheatmap(test, scale = "row", clustering_distance_rows = "correlation")
![90f1a917443f4f4e28c1287010d3b8ba.png](https://img-blog.csdnimg.cn/img_convert/90f1a917443f4f4e28c1287010d3b8ba.png)
#自定义颜色
pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))
![788d0cd9a42afc736e842dbafe7c1723.png](https://img-blog.csdnimg.cn/img_convert/788d0cd9a42afc736e842dbafe7c1723.png)