Question: ComplexHeatmap Scale by Row
0
gravatar for andrew.j.skelton73
4.5 years ago by
United Kingdom
andrew.j.skelton73320 wrote:

Hi, 

I'd like to scale by row, similar to a feature in heatmap.2 for the complexHeatmap package and wondered if there was a way anyone knows of? 

Cheers

heatmap complexheatmap • 4.1k views
ADD COMMENTlink modified 4.5 years ago by James W. MacDonald51k • written 4.5 years ago by andrew.j.skelton73320
Answer: ComplexHeatmap Scale by Row
2
gravatar for James W. MacDonald
4.5 years ago by
United States
James W. MacDonald51k wrote:

Sure. Use the scale() function on your matrix, then feed it to Heatmap().

ADD COMMENTlink written 4.5 years ago by James W. MacDonald51k

Thanks for the simple answer! 

ADD REPLYlink written 4.5 years ago by andrew.j.skelton73320

Interestingly, when I went and took a look at the heatmap.2 code for scale by row, it's: 

rm            <- rowMeans(x)
x             <- sweep(x, 1, rm)
sx            <- apply(x, 1, sd)
x             <- sweep(x, 1, sx, "/")​
ADD REPLYlink written 4.5 years ago by andrew.j.skelton73320
2

Right. The scale() function works on the columns, so you have to do some transposing.

> z <- matrix(rnorm(100),10)
> rm <- rowMeans(z)
> sx <- apply(z, 1, sd)
> zz <- sweep(z,1,rm)
> zz <- sweep(zz, 1, sx, "/")
> zzz <- t(scale(t(z)))
> all.equal(zz, zzz, check.attributes = FALSE)
[1] TRUE

 

ADD REPLYlink modified 4.5 years ago • written 4.5 years ago by James W. MacDonald51k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 305 users visited in the last hour