在 pheatmap 中使用热图的特定值进行绘图

plotting with specific values for heatmap in 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 制作一个热图,如果任何东西低于 -4,它应该是绿色的,任何超过 +4 的东西应该是红色的,并且介于两者之间的所有东西都应该 red/green 阴影。我也不想扩展我的数据并且没有集群。到目前为止,我在 R:

中有这段代码
d <- read.table("test.txt", header = TRUE, sep = "\t", row.names = 1, quote = "")

pheatmap(as.matrix(d),  # matrix
         scale = "none",         # z score scaling applied to rows 
         cluster_cols=FALSE,    # do not cluster columns
         cluster_rows = FALSE,
         treeheight_row=0,      # do not show row dendrogram
         show_rownames=FALSE,   # do not show row names i.e gene names
         main = "test.txt",
         color = colorRampPalette(c("#0016DB","#FFFFFF","#FFFF00"))(50),
         )

如何使用我上面提到的配色方案来绘制它。

谢谢

d <-read.table(text="gene      s1      s2      s3
                        1   -3.83   -8.17   -8.59
                        2    0.33   -4.51   -7.27
                        3    0.15   -5.26   -6.20  
                        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.40
                        9   -0.72   -3.37   -4.39", header=T)

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 = "none",         
         cluster_cols=FALSE,    
         cluster_rows = FALSE,
         treeheight_row=0,      
         show_rownames=FALSE,   
         main = "test.txt",
         color = my_palette,
         breaks = my_colors)

reprex package (v0.3.0)

于 2019-05-29 创建