Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R-Heatmap.2 Remove huge space left between title and actual heatmap after disabling column dendrogram

Tags:

r

heatmap

I am plotting a 759*12 double matrix twoway.expr.005 using heatmap.2()

library(gplots)
dist2 <- function(x, ...){as.dist(1-cor(t(x), method="pearson"))}
heatmap.2(x=twoway.expr.005,col=bluered(75), main="Heatmap:759 genes\nTwosided Pval<0.05",tracecol= NULL, cexCol=0.8,cexRow=0.5,labCol=labs,distfun=dist2,scale="row",key=F,dendrogram='row',Colv=F)

But because I am setting dendrogram='row' (column dendrogram turned off) and key=F, my heatmap is leaving a huge whitespace between the title of the plot and the actual plot when I try to save it as a PDF.

enter image description here

I tried setting lhei as per the suggestion. I have used lhei=c(1,4) but it still shows me a LOT of space between the title and the plot:

heatmap.2(x=twoway.expr.005,col=bluered(75), main="Heatmap:759 genes\nTwosided Pval<0.05",tracecol= NULL, cexCol=0.8,cexRow=0.5,labCol=labs,distfun=dist2,scale="row",key=F,dendrogram='row',Colv=F,lhei=c(1,4))

enter image description here

Setting lhei=c(1,5) completely throws away the title:

heatmap.2(x=twoway.expr.005,col=bluered(75), main="Heatmap:759 genes\nTwosided Pval<0.05",tracecol= NULL, cexCol=0.8,cexRow=0.5,labCol=labs,distfun=dist2,scale="row",key=F,dendrogram='row',Colv=F,lhei=c(1,5))

enter image description here

I think Heatmap.2 is designed in such a way that the title is always placed above the column dendrogram. So if the column dendrogram is disabled, it leaves an empty space but the position of the title is still above the "disabled" column dendrogram. Is there any way to hack the code so that the title is not placed above the column dendrogram (which may be the solution to this problem)? What else can be done to remove the space between the title & the actual plot?

like image 446
Komal Rathi Avatar asked Oct 18 '13 15:10

Komal Rathi


1 Answers

The lhei argument to heatmap.2 can be used to fix this. It takes a vector of length 2 that represent the relative heights of the rows of the layout of the plot.

Heatmap.2 divides the plot area in to a four blocks using the layout function. Essentially, you want to control the height of the first one relative to the second. To do this, set lhei to something like c(1, 10). This will make the bottom row, which is where the heatmap is, 10 times as tall as the top row which normally has the dendogram for the rows and the color key.

The documentation for layout has more details.

like image 182
Christopher Louden Avatar answered Sep 21 '22 12:09

Christopher Louden