第五课 热图
参考教程
https://blog.csdn.net/u013429737/article/details/123847564
1.pheatmap包的测试数据
test = matrix(rnorm(200), 20, 10) #rnorm()函数用来产生一个随机矩阵数据,200个,20行,10列
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3 #选取test中1-10行,1-10列中的步长为2的数据,也就是1,3,5,7,9列的数据。把这些数+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 = "") # 把列名设定为Test1-10
rownames(test) = paste("Gene", 1:20, sep = "") #行名Gene1-20
pheatmap(test)
pheatmap(test, scale = "row", clustering_distance_rows = "correlation") #先把每一行均一化,避免不同基因的基本表达水平差异带来的热图分辨率差。
pheatmap(test, scale = "row", clustering_distance_rows = "correlation", color = colorRampPalette(c("navy", "white", "firebrick3"))(50)) #换个颜色蓝白红,(50)参数表示分成的色阶,数越大图越细腻。
- 合并数据
> a1=rnorm(100)
> dim(a1)=c(5,20)
> a2=a1+2
> pheatmap(cbind(a1,a2)) #把a1,a2按照列合并,即行数不变,列数增加。
在对行列名进行设定
> rownames(a1)=paste("Gene",sep="_",1:5)
> rownames(a2)=paste("Gene",sep="_",1:5)
> colnames(a1)=paste("Test_a1",sep="_",1:20)
> colnames(a2)=paste("Test_a2",sep="_",1:20)
> pheatmap(cbind(a1,a2))
> pheatmap(cbind(a1,a2),color = colorRampPalette(c("navy", "white", "firebrick3"))(50)) #再改成喜欢的颜色

3.组别注释
annotation_col = data.frame(
CellType = factor(rep(c("CT1", "CT2"), 5)),
Time = factor(rep(c("0min","1min","3min","5min","10min"),2))) #建立一个数据框有两列CellType和Time两列,分别对应一些组别标识。
rownames(annotation_col) = paste("Test", 1:10, sep = "") #对这个数据框进行行注释
pheatmap(test, annotation_col = annotation_col,main="Example heatmap")
#做图能显示不同组别

网友评论