adhg
adhg

Reputation: 10853

R heatmap - requesting visualization with correlation to all variables

I'm trying to build a 'heatmap' based on this tutorial. My data.frame looks like this:

enter image description here

and the result looks like this:

enter image description here

Code:

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))

My question is this: if you look at the data.frame for Bing and Baidu on March (marked in yellow) the result on the heat map is identical (both strong red). I assume the heatmap show the colors with respect to the specific 'search engine' over the period of months and not with respect to all other search engines. So how can I set-up the heatmap in such way that the color-result will be relatively to all the other search-engines? I expect to see red-ish' color Bing in march.

Upvotes: 1

Views: 530

Answers (1)

Byron Wall
Byron Wall

Reputation: 4010

You can change the scaling with the scale parameter. Changing that to "none" will prevent the rescaling across the column before the colors are drawn. The final line of code below is what you want.

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))

Images:

Here is the scale="column": scale on columns

And here is the scale="none": scale on none

Upvotes: 2

Related Questions