提出这个问题是在R package:circlize环状热图需要对某个矩阵进行归一化处理,
虽然在pheatmap包,有一个归一化参数scale,有 "row", "column" 和"none"。但是在这里,我们需要自己做归一化并得到归一化后的矩阵。其实,R里面有一个归一化的函数scale,那么scale函数对矩阵归一化是按行归一化,还是按列归一化呢?在scale的帮助文档里,由于没有找到相关说明,只能自己作一番测试。
set.seed(123)#设置随机数,方便重复
matrix = matrix(rnorm(36), nrow = 6, ncol = 6)
matrix
这是一个6*6的矩阵
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.56047565 0.4609162 0.4007715 0.7013559 -0.6250393 0.4264642
[2,] -0.23017749 -1.2650612 0.1106827 -0.4727914 -1.6866933 -0.2950715
[3,] 1.55870831 -0.6868529 -0.5558411 -1.0678237 0.8377870 0.8951257
[4,] 0.07050839 -0.4456620 1.7869131 -0.2179749 0.1533731 0.8781335
[5,] 0.12928774 1.2240818 0.4978505 -1.0260044 -1.1381369 0.8215811
[6,] 1.71506499 0.3598138 -1.9666172 -0.7288912 1.2538149 0.6886403
1,首先使用scale对其归一化处理
mat = scale(matrix, center = TRUE, scale = TRUE)
mat
归一化后的矩阵
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] -1.0551056 0.5746036 0.28474835 1.776408011 -0.3696184 -0.3118066
[2,] -0.7092445 -1.3336767 0.05216076 -0.006229502 -1.2946186 -1.8886046
[3,] 1.1639297 -0.6943963 -0.48224529 -0.909631389 0.9049161 0.7123761
[4,] -0.3943910 -0.4277301 1.39613020 0.380643113 0.3085984 0.6752425
[5,] -0.3328421 1.4183770 0.36258446 -0.846139716 -0.8166712 0.5516565
[6,] 1.3276535 0.4628225 -1.61337847 -0.395050517 1.2673937 0.2611361
2,然后使用pheatmap包scale参数对原始矩阵归一化处理
2.1 按行
p1=pheatmap(matrix,scale = "row",
display_numbers = T,
cluster_rows = F,
cluster_cols = F)
p1
Fig1.png
2.1 按列
p2=pheatmap(matrix,scale = "column",
display_numbers = T,
cluster_rows = F,
cluster_cols = F)
p2
Fig2.png
通过比较发现scale函数是按列归一化,对于我们一般习惯基因名为行,样本名为列的数据框,就需要进行转置
t(matrix)
网友评论