Pheatmap and SD
1
0
Entering edit mode
4.7 years ago
Morris_Chair ▴ 360

Hello everyone,

I have to generate a Heatmap using Pheatmap package in R

The heatmap as to be scaled by row with mean = 0 and SD = 1.

Now my command line is this:

pheatmap(data,scale = "row")

I can tell that scaling by row makes a good difference but how can I set a mean = 0 and SD = 1 ?

Thanks for help

RNA-Seq • 1.3k views
ADD COMMENT
2
Entering edit mode
4.7 years ago

Hey Morris,

You are doing it correctly as is. The pheatmap row-scaling function is the following:

pheatmap.scale <- function(x) {
  m = apply(x, 1, mean, na.rm = T)
  s = apply(x, 1, sd, na.rm = T)
  return((x - m) / s)
}

Let's create random data:

randomdata <- matrix(rexp(2000000, rate=.1), ncol=2000)

Now let's scale with pheatmap()'s row-scaling function:

randomdata.scaled <- pheatmap.scale(randomdata)

Now check the mean and sd of each row:

all(round(apply(randomdata.scaled, 1, mean), 3) == 0)
[1] TRUE

all(round(apply(randomdata.scaled, 1, sd), 3) == 1)
[1] TRUE

---------------------------

Note that this is exactly the same as scaling outside of pheatmap(), like this:

randomdata.scaled <- t(scale(t(randomdata)))

all(round(apply(randomdata.scaled, 1, mean), 3) == 0)
[1] TRUE

all(round(apply(randomdata.scaled, 1, sd), 3) == 1)
[1] TRUE

------------------------------

So —don't worry— you are doing it correctly.

Kevin

ADD COMMENT

Login before adding your answer.

Traffic: 1032 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6