ComplexHeatmap Scale by Row
1
0
Entering edit mode
@andrewjskelton73-7074
Last seen 8 months ago
United Kingdom

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

ComplexHeatmap heatmap • 10.0k views
ADD COMMENT
2
Entering edit mode
@james-w-macdonald-5106
Last seen 14 hours ago
United States

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

ADD COMMENT
0
Entering edit mode

Thanks for the simple answer! 

ADD REPLY
0
Entering edit mode

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 REPLY
2
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 825 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