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?
Sure. Use the scale() function on your matrix, then feed it to Heatmap().
Thanks for the simple answer!
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, "/")
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)
Login before adding your answer.
Use of this site constitutes acceptance of our User Agreement and Privacy