首页 文章

对于r中的某些值,具有自己颜色的热图

提问于
浏览
4

这是数据:

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

1 回答

  • 4

    也许...

    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

相关问题