r - r 中某些值的具有自己颜色的热图图

标签 r colors scale heatmap

这是数据:

set.seed(123)
mat <- matrix(rnorm(5000, 0.5, 0.2), 50)
heatmap (mat)

enter image description here
mat[mat > 0.05] <- NA
heatmap (mat)

Error in hclustfun(distfun(x)) : 
  NA/NaN/Inf in foreign function call (arg 11)

通过用其他值替换(任意可以帮助),但它可以欺骗读者,因为它会从相同的比例中选择颜色,这是不正确的。所以我想为那些大于 0.05 的值设置完全不同的颜色。
mat[mat > 0.05] <- 0.1
heatmap (mat)

enter image description here

最佳答案

也许...

library(gplots)
set.seed(123)
mat <- matrix(rnorm(5000, 0.5, 0.2), 50)
heatmap.2(mat, breaks=c(-1,0.02,0.05,1), col=c("yellow", "red", "blue"), 
# aiming for >0.05 is blue
dendrogram="both", trace="none")

基本上玩玩col=breaks=
好像:

enter image description here

关于r - r 中某些值的具有自己颜色的热图图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572862/

相关文章:

r - 使用基于数据/类类型的 if 语句映射

JavaScript 无法使按钮改变框的颜色

javascript - 使动画在过渡后运行

r - ggplot2 中的等高线

R(dplyr): find all rows in row-specific range

R 4.0.0 : I am trying to change symbols of legend for a plot in ggplot2, 目前我有重叠的符号

python - 将 PMML 模型导入 Python (Scikit-learn)

text - Flutter-如何在黑暗模式下更改状态栏文本的颜色?

svn - 根据 svn 状态为文件名着色

css - 变换 : scaleX() seems to change element's height