Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R pheatmap: use logarithmic scaling in the legend

Tags:

r

pheatmap

I have a matrix

library(pheatmap)
set.seed(1)
mat <- matrix(rexp(200, rate=.001), ncol=20)
pheatmap(mat)

and there is one value that is much higher than the rest. Therefore, I would like to use a logarithmic scaling for the legend bar (1, 10, 100, 1000, ...).

Is there a possibility to do that with the pheatmap package?

EDIT: I don't want to make log(mat), I only want the color scaling bar be scaled logarithmic (1, 10, 100, 1000, ...).

like image 615
Revan Avatar asked Nov 30 '25 01:11

Revan


1 Answers

Just add logarithmic legend_breaks and show a label for the maximum.

pheatmap::pheatmap(mat, legend_breaks=c(10^(0:ceiling(log10(max(mat)))), 
                                        round(max(mat), 2)))

Yielding

plot

like image 77
jay.sf Avatar answered Dec 02 '25 17:12

jay.sf