Question: (Closed) R programming: Keep Heatmap Items Within Image Frame
gravatar for dec986
5.5 years ago by
United States
dec986230 wrote:


I am trying to keep my heatmap column labels within the borders of the image.

This is my code:

#Notes from
#this comes from a csv file made by
for (sex in c("male","female")) {
    filename <- paste("arranged_read_",sex,".csv",collapse=NULL,sep="")
    data <- read.csv(filename, header = T, stringsAsFactors=F)
    row.names(data) <- data$Gene.Symbol
    data <- data[,2:7]
#make heatmap normalized by row
    filename <- paste(sex,"_heatmap_normRow.png",collapse=NULL,sep="")
    heatmap.2(as.matrix(data), col=redgreen(75), scale="row", key=T, keysize=1.5,"none", trace="none",cexCol=0.5, labRow=NA)
#make heatmap normalized by column
    filename <- paste(sex,"_heatmap_normColumn.png",collapse=NULL,sep="")
    heatmap.2(as.matrix(data), col=redgreen(75), scale="column", key=T, keysize=1.5,"none", trace="none",cexCol=0.9, labRow=NA)
    data <-log2(data)
    data2 = normalize.quantiles(as.matrix(data))
    rownames(data2) = rownames(data)
    colnames(data2) = colnames(data)
    filename <- paste(sex,"_boxplot.png",collapse=NULL,sep="")
    boxplot(data2, cex.axis=0.8, las=2, main="Distribution after normalization",ylab="Log2(Intensity)")#boxplot command writes to boxplot.png

However the labels run off of the page.  Resizing the image just stretches the labels, and I can't shrink the label font size, as the label isn't legible.

Much appreciated,


rna-seq R • 3.3k views
ADD COMMENTlink written 5.5 years ago by dec986230

Hello dec986!

We believe that this post does not fit the main topic of this site.

Not really a bioinformatics question, but a pure R question. Note the margins= parameter in heatmap.2()

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink modified 5.5 years ago • written 5.5 years ago by Devon Ryan96k

Hi Devon,

I disagree that this should be closed.  I came here for help in bioinformatics, which is the topic of this site as far as I understand, and could not find answers on Google searches.

ADD REPLYlink written 5.5 years ago by dec986230

I understand that, but your question, as presented can be rewritten, "How do I get heatmap.2 to not clip off row/column labels?". That's purely an R question. Note also that I gave you the answer above with the margins= parameter. :o)

There's unfortunately not a way to tell heatmap.2() to auto-adjust margins so that labels don't get clipped.

ADD REPLYlink written 5.5 years ago by Devon Ryan96k

Devon is right,

you should probably ask this question on stack overflow



is your solution in heatmap.2

ADD REPLYlink modified 5.5 years ago • written 5.5 years ago by Manvendra Singh2.1k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 891 users visited in the last hour