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

Hello,

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

This is my code:


#Notes from http://mannheimiagoesprogramming.blogspot.com/2012/06/drawing-heatmaps-in-r-with-heatmap2.html
#this comes from a csv file made by make_heatmap.pl
library(gplots)
for (sex in c("male","female")) {
    print(sex)
    filename <- paste("arranged_read_",sex,".csv",collapse=NULL,sep="")
    print(filename)
    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="")
    png(filename=filename)
    heatmap.2(as.matrix(data), col=redgreen(75), scale="row", key=T, keysize=1.5,density.info="none", trace="none",cexCol=0.5, labRow=NA)
#make heatmap normalized by column
    filename <- paste(sex,"_heatmap_normColumn.png",collapse=NULL,sep="")
    png(filename=filename)
    heatmap.2(as.matrix(data), col=redgreen(75), scale="column", key=T, keysize=1.5,density.info="none", trace="none",cexCol=0.9, labRow=NA)
#
    data <-log2(data)
    library(preprocessCore)
    data2 = normalize.quantiles(as.matrix(data))
    rownames(data2) = rownames(data)
    colnames(data2) = colnames(data)
    filename <- paste(sex,"_boxplot.png",collapse=NULL,sep="")
    png(filename=filename)
    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,

-Dave

rna-seq R • 2.2k views
ADD COMMENTlink written 4.0 years ago by dec986160
2

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.

Cheers!

ADD REPLYlink modified 4.0 years ago • written 4.0 years ago by Devon Ryan88k

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 4.0 years ago by dec986160
1

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 4.0 years ago by Devon Ryan88k

Devon is right,

you should probably ask this question on stack overflow

btw

​margin=c(<vertical>,<horizontal>), 

is your solution in heatmap.2

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

Help
Access

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