4

I have:

library(gplots);
x<-matrix(seq(1:100),nrow=10,byrow=TRUE);
heatmap.2(x, Rowv=NA, Colv=NA, scale="none", main="This title will be cut off by the white space where the non-existant key is supposed to go.", col=gray((255:0)/255), dendrogram="none",trace="none", key=FALSE);

When the key is specified as FALSE, there's a block of white-space on the left side of the plot that prevents the full title from showing up, conflicts with manual specification of smaller margins, and moves the heat-map toward the right. The width of the white-space is controllable using "keysize=#", but making it too small (somewhere between 0.8 and 1.0) creates an error: "Error in plot.new() : figure margins too large"

I would try doing this with heatmap() instead of heatmap.2(), but heatmap doesn't play well with par() which I need for a project. If anyone has any suggestions, I'd appreciate it.

Steve P.
  • 14,489
  • 8
  • 42
  • 72
user2407829
  • 43
  • 1
  • 1
  • 4

1 Answers1

4

Positioning elements of the heatmap.2 plot can be done using the layout parameter(s).

layout(mat = lmat, widths = lwid, heights = lhei)

I get a pretty acceptable heatmap plot using the following.

heatmap.2(x, 
    Rowv=NA, 
    Colv=NA, 
    scale="none", 
    main="This title will be cut off by the white space where the non-existant key is supposed to go.", 
    col=gray((255:0)/255), 
    dendrogram="none",
    trace="none", 
    key=FALSE, 
    lmat=rbind(c(2),c(3),c(1),c(4)), 
    lhei=c(1,1,9,0), 
    lwid=c(1)
    );

Please refer to ?layout or this answer on Stack Exchange for more details.

Community
  • 1
  • 1
Lukas Vermeer
  • 5,920
  • 2
  • 16
  • 19
  • I'm trying to remove an element, not reposition it. The answer on that Stack Exchange page is regarding edits that are suggested to the heatmap.2() function, not ways to fix the issue within one's R-script. – user2407829 May 22 '13 at 16:58
  • I don't think it's possible to completely remove elements from the layout; repositioning seems to be the way to go. – Lukas Vermeer May 23 '13 at 07:17
  • 1
    I am facing same problem here, can we adjust heatmap to the center of plot, because its going at the rightmost end. A lot whitespace from left to heatmap is unacceptable. Appreciate any help friends.. – indra_patil May 15 '14 at 06:41
  • I'm in the same position as well. Really wish there was an argument of heatmap.2 that lets you place the matrix itself in the top left, top right etc corners, and then if someone wanted the key etc have it move to the opposite side from that. – Laserhedvig Feb 15 '20 at 19:17