I read the heatmap.2 help manual a couple of times now, and also in various online tutorials I didn't read about a way to move the color key to a different position. Now, I am wondering if it is even possible?
The color key is in the upper left corner by default if you are using the heatmap.2 function from the gplots package.
The position of each element in the
heatmap.2
plot can be controlled using thelmat
,lhei
andlwid
parameters. These are passed byheatmap.2
to thelayout
command as:lmat
is a matrix describing how the screen is to be broken up. By default, heatmap.2 divides the screen into a four element grid, solmat
is a 2x2 matrix. The number in each element of the matrix describes what order to plot the next four plots in. Heatmap.2 plots its elements in the following order:so the default
lmat
is:If for example, you want to put the key underneath the heatmap you would specify:
lwid
andlhei
are vectors that specify the height and width of each row and column. The default isc(1.5,4)
for both. If you changelmat
you'll either have to or probably want to change these as well. For the above example, if we want to keep all the other elements the same size, but want a thin color key at the bottom, we might setWe are then ready to plot the heatmap:
This will plot a heatmap with the column dendrogram above the heatmap, the row dendrogram to the left, and the key underneath. Unfortunately the headings and the labels for the key are hard coded.
see
?layout
for more details on howlayout
works.There are specified regions defined by par calls in the rather long code for
heatmap.2
and I have not seen its original author or any of the "revisors" around these parts, although they sometimes visit on R-help. The main plot dimensions are set by the 2-element vectormargins
. Here are some places where you might need to make changes: