仅根据值对热图进行着色!= 0

问题描述 投票:0回答:1

我有这个数据框:

     head(df)                                            gene1    gene2     gene3
leukocyte activation involved in immune response        0             0         0.5
cell activation involved in immune response             0            -1         2
alpha-beta T cell activation                            0.3           1         0
alpha-beta T cell differentiation                       0            -0.8      -0.2
positive regulation of cytokine production              1.7           0        -1
leukocyte differentiation                               0             0         1

请问如何才能只为不为零的值着色?我想将 0 值保留为白色。 我用过

my_col <- colorRampPalette(c("blue", "white", "red"))(101)  

pheatmap(df, 
         cluster_rows = TRUE,  
         cluster_cols = TRUE, 
         fontsize_row = 8,     
         fontsize_col = 8,
         color = my_col)

但这是错误的,因为我不想在色阶中包含 0,我希望默认情况下零值是白色的,如下例所示: enter image description here

谢谢你

r heatmap pheatmap
1个回答
0
投票

使用

breaks
应给出所需的结果

pheatmap(mat, 
         cluster_rows = TRUE,  
         cluster_cols = TRUE, 
         fontsize_row = 8,     
         fontsize_col = 8,
         color = my_col, 
         breaks=seq(-max(mat), max(mat), length.out=length(my_col) + 1))
© www.soinside.com 2019 - 2024. All rights reserved.