r - 在 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 的东西都应该是红色的,介于两者之间的所有东西都应该是红色/绿色阴影。我也不想扩展我的数据并且没有聚类。到目前为止,我在 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 包(v0.3.0)于 2019 年 5 月 29 日创建
推荐阅读
- python - 如何使用重采样计数筛选原始数据
- java - 如何在quarkus上设置http线程池最大大小
- python - kaggle:在 ubuntu 18 上找不到命令
- android - 使用 Cordova 在 Android 上通过 Apple 登录
- javascript - 错误:expiresIn 应该是秒数或字符串代表
- r - 通过单击列名排列 kable 交互式表格
- node.js - 想知道,如何使用 Gridfs 使用 express、mongoose、mongodb 上传超过 16mb 的文件/视频
- sql - 根据日期从多个表中获取 TOP 1 行
- java - C# AES 加密到 java 8 解密
- javascript - 如何存储来自另一个组件数据的值?