I could not find a way to set axis label size for the heatmap itself. The cex.lab
argument passed to heatmap.2
has no effect. Calling par(cex.lab = 2.5)
has an effect on the legend axis labels and title (these all together, I can`t imagine what if one would like to change only the title…). Anyways, my question is about the heatmap axis label sizes. Example code:
require(gplots)
data(mtcars)
x <- as.matrix(mtcars)
heatmap.2(x, ylab = 'foo bar', xlab = 'bar foo')
par(cex.lab = 5.0)
heatmap.2(x, ylab = 'foo bar', xlab = 'bar foo')
Best Answer
Inspecting
heatmap.2
code it is not possible by design.heatmap.2
callsimage
to draw the heatmap, and extra keyword args (...
) passed to it, hence callingheatmap.2(..., cex.lab = n, ...)
would make it, andimage
considerspar
, so also that way it could be possible. But herexlab
andylab
are replaced with empty strings, and both the ticklabels and the axis labels are plotted later:Then to draw the axis labels it uses
mtext
, which is not sensitive topar
parameters, but acceptscex
argument, which is not provided here:It means these labels are always the same size, while heatmaps are huge sometimes, so this might be a problem. Also one could maybe shrink the graphic device, and all the other text elements which have the options for customization, and then the relative size of the axis labels would be larger. But how we could sort this out a more flexible way? I modified the code like this:
The only problem is the positioning parameter which is now
cex.lab / 5
, this avoids overlap with ticklabels in reasonable ranges, but maye another parameter should be added to the function, so users can modify if it does not fit.You can copy
heatmap.2.R
fromgplots
source into your working dir, modify it and source it:However you need to add also these lines to the beginning: