Off topic:R programming: Keep Heatmap Items Within Image Frame
0
0
Entering edit mode
9.1 years ago
dec986 ▴ 370

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

R RNA-Seq • 4.3k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2826 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6