2015-04-07 837 views
0

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

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)" 
+0

您在错误消息中有答案。查看'class(c)'的结果。并且请避免使用'c'作为变量的名称。 – 2015-04-07 08:27:54

回答

0

?heatmap

ColSideColors (optional) character vector of length ncol(x) containing the color names for a horizontal side bar that may be used to annotate the columns of x.

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

enter image description here