2015-04-07 80 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