R - gplots - Removing white space in heatmap.2 when key=FALSE

12,417

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.

Share:
12,417
Admin
Author by

Admin

Updated on July 28, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • Admin
    Admin about 11 years
    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.
  • Lukas Vermeer
    Lukas Vermeer about 11 years
    I don't think it's possible to completely remove elements from the layout; repositioning seems to be the way to go.
  • indra_patil
    indra_patil about 10 years
    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..
  • Laserhedvig
    Laserhedvig over 4 years
    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.