R programming: Keep Heatmap Items Within Image Frame
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
• 4,443 views
•
link
0 answers
No answers yet.
Log in to answer this question.
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 inheatmap.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!
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.
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.
Devon is right,
you should probably ask this question on stack overflow
is your solution in
heatmap.2