R - 热图,设置ColSideColors

时间:2015-04-07 08:24:10

标签: r colors heatmap

我可以使用palette()在热图的行和列上设置颜色标签吗? 我制作一个随机的4x4矩阵,绘制热图并尝试设置侧面颜色:

m <- matrix(rnorm(16), 4, 4)
c <- c(1,1,2,2)
heatmap(m,ColSideColors=c)

我收到错误:

"Error in heatmap(m, ColSideColors = c) : 
  'ColSideColors' must be a character vector of length ncol(x)"

1 个答案:

答案 0 :(得分:0)

来自?heatmap

  

ColSideColors(可选)长度为ncol(x)的字符向量,包含可用于注释x列的水平侧栏的颜色名称。

set.seed(42)
m <- matrix(rnorm(16), 4, 4)
xsidecols <- c("#cdcd0d", "#0dcdcd", "#cd0dcd", "grey")
heatmap(m, ColSideColors = xsidecols)

enter image description here