1

我对 pheatmap 中的行缩放有点困惑。这是我的数据框

gene    s1  s2  s3
1   -3.83   -8.17   -8.59
2   0.33    -4.51   -7.27
3   0.15    -5.26   -6.2
4   -0.08   -6.13   -5.95
5   -1.15   -4.82   -5.75
6   -0.99   -4.11   -4.85
7   0.42    -4.18   -4.54
8   -0.32   -3.43   -4.4
9   -0.72   -3.37   -4.39

在 pheatmap 生成具有行 z 分数的图形后,我需要提取数据帧的这些值

library(pheatmap)

my_colors <- c(min(d),seq(-4,4,by=0.01),max(d))

my_palette <- c("green",colorRampPalette(colors = c("green", "red"))
                (n = length(my_colors)-2), "red")
pheatmap(as.matrix(d),  
         scale = "row",         
         cluster_cols=FALSE,    
         cluster_rows = FALSE,
         treeheight_row=0,      
         show_rownames=FALSE,   
         main = "test.txt",
         color = my_palette,
         breaks = my_colors)

我怎样才能得到一个 pheatmap 用来制作热图的新矩阵?

4

1 回答 1

0
scale_rows = function(x){
    m = apply(x, 1, mean, na.rm = T)
    s = apply(x, 1, sd, na.rm = T)
    return((x - m) / s)
}

zscores <- scale_rows(matrix)

https://github.com/raivokolde/pheatmap/blob/44a44f7e640c73867f40261691c16dfa4da34fa8/R/pheatmap.r

于 2021-11-01T19:45:14.750 回答