How does heatmap3 go from value to colour?
I'm using the heatmap3 package for R to generate some gene expression data heatmaps.
My question is: how are the values for the gene expression being "mapped" to colours?
As an example of the same (reproducible) problem, lets use the example code in the vignette on the mtcars dataset:
library(heatmap3)
heatmap3(mtcars,scale="col",margins=c(2,10),RowSideColors=RowSideColors, balanceColor = TRUE)
The legend shows that the colours range from approximately -2 to plus 3. If we use the Maserati Bora as an example
mpg cyl disp hp drat wt qsec vs am gear carb 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
We can see in the heatmap that it has a bright red colour ie a score of ~3 for carb and a blue score of about -1.5 for qsec.
Looking at the other cars in the dataset, they have the following carb:
4 4 1 1 2 1 4 2 2 4 4 3 3 3 4 4 4 1 2 1 1 2 2 4 2 1 2 2 4 6 8 2
So the Maserati Bora is definitely an outlier in terms of carbon, as is the Ferrari Dino (carb = 6), which is also as expected red in the heatmap.
Similarly, looking at the qseq
16.46 17.02 18.61 19.44 17.02 20.22 15.84 20.00 22.90 18.30 18.90 17.40 17.60 18.00 17.98 17.82 17.42 19.47 18.52 19.90 20.01 16.87 17.30 15.41 17.05 18.90 16.70 16.90 14.50 15.50 14.60 18.60
The Maserati's 14.60 is close to the minimum of 14.5, which is observed in the Ford Pantera L, which is also blue, as we'd expect.
But how are we actually going from the value to the colour? What is the formula for calculating this z-score? And is it being averaged out on a per-car or a per-parameter (mpg, cyl etc) basis?
OK, I think I just figured it out - but posting here in case others have the same problem:
It's using the basic z-score formula, so
(mtcars$qsec - mean(mtcars$qsec))/sd(mtcars$qsec)
(value - pop_mean(value))/ sd(value)
链接地址: http://www.djcxy.com/p/30958.html
上一篇: 如何用R格式化包更改表格标题行的外观
下一篇: heatmap3如何从价值转变为色彩?