2015-04-02 94 views
0

我試圖根據this教程構建「熱圖」。我data.frame看起來是這樣的:R熱圖 - 請求可視化與所有變量的相關性

enter image description here

,結果是這樣的:

enter image description here

代碼:

row.names(data) <-data$X) 
data<-data[,2:5] 
data_matrix<-data.matrix(data) 
heat_result<-heatmap(data_matrix, Rowv=NA, Colv=NA, col = heat.colors(256), scale="column", margins=c(5,10)) 

我的問題是這樣的:如果你看看在3月份Bing和百度的data.frame(用黃色標出)時,熱圖上的結果是相同的(都是強紅色的)。我假設熱圖在幾個月的時間內顯示與特定「搜索引擎」相關的顏色,而不是所有其他搜索引擎。那麼我怎樣才能以這樣的方式設置熱圖,即顏色結果將與所有其他搜索引擎相對?我期待在三月看到紅色的冰彩。

回答

1

您可以使用比例參數更改比例。將其更改爲「無」將防止在繪製顏色之前在列上重新縮放。下面的代碼的最後一行是你想要的。

https://stat.ethz.ch/R-manual/R-devel/library/stats/html/heatmap.html

set.seed(42) 

#uniform sampling, b is much larger than a 
a = runif(10,1,10) 
b = runif(10,10,100) 

data = as.matrix(cbind(a,b)) 

#scale across columns 
heatmap(data, Rowv=NA, Colv=NA, col = heat.colors(256), scale="column", margins=c(5,10)) 

#color across whole dataset. 
heatmap(data, Rowv=NA, Colv=NA, col = heat.colors(256), scale="none", margins=c(5,10)) 

圖片:

這裏是規模= 「列」: scale on columns

這裏是規模= 「無」: scale on none

+0

做的絕招,謝謝 – adhg 2015-04-02 14:58:04