[R-gregmisc-users] SF.net SVN: r-gregmisc:[1724] trunk/gplots
Brought to you by:
warnes
From: <wa...@us...> - 2013-10-11 20:19:25
|
Revision: 1724 http://sourceforge.net/p/r-gregmisc/code/1724 Author: warnes Date: 2013-10-11 20:19:22 +0000 (Fri, 11 Oct 2013) Log Message: ----------- Add parameters to control row and column label positioning, rotation, justification, and offset. Modified Paths: -------------- trunk/gplots/R/heatmap.2.R trunk/gplots/man/heatmap.2.Rd Modified: trunk/gplots/R/heatmap.2.R =================================================================== --- trunk/gplots/R/heatmap.2.R 2013-10-11 17:15:54 UTC (rev 1723) +++ trunk/gplots/R/heatmap.2.R 2013-10-11 20:19:22 UTC (rev 1724) @@ -52,6 +52,12 @@ cexCol = 0.2 + 1/log10(nc), labRow = NULL, labCol = NULL, + srtRow = NULL, + srtCol = NULL, + adjRow = c(0,NA), + adjCol = c(NA,0), + offsetRow = 0.5, + offsetCol = 0.5, ## color key + density info key = TRUE, @@ -389,10 +395,79 @@ col=na.color, add=TRUE) } - ## add labels - axis(1, 1:nc, labels= labCol, las= 2, line= -0.5, tick= 0, cex.axis= cexCol) + ## add column labels + if(is.null(srtCol)) + axis(1, + 1:nc, + labels= labCol, + las= 2, + line= -0.5 + offsetCol, + tick= 0, + cex.axis= cexCol, + hadj=adjCol[1], + padj=adjCol[2] + ) + else + { + if(is.numeric(srtCol)) + { + if(missing(adjCol) || is.null(adjCol)) + adjCol=c(1,NA) + + xpd.orig <- par("xpd") + par(xpd=NA) + xpos <- axis(1, 1:nc, labels=rep("", nc), las=2, tick=0) + text(x=xpos, + y=par("usr")[3] - (1.0 + offsetCol) * strheight("M"), + labels=labCol, + ##pos=1, + adj=adjCol, + cex=cexCol, + srt=srtCol) + par(xpd=xpd.orig) + } + else + warning("Invalid value for srtCol ignored.") + } + + ## add row labels + if(is.null(srtRow)) + { + axis(4, + iy, + labels=labRow, + las=2, + line=-0.5+offsetRow, + tick=0, + cex.axis=cexRow, + hadj=adjRow[1], + padj=adjRow[2] + ) + } + else + { + if(is.numeric(srtRow)) + { + xpd.orig <- par("xpd") + par(xpd=NA) + ypos <- axis(4, iy, labels=rep("", nr), las=2, line= -0.5, tick=0) + text(x=par("usr")[2] + (1.0 + offsetRow) * strwidth("M"), + y=ypos, + labels=labRow, + adj=adjRow, + cex=cexRow, + srt=srtRow + ) + par(xpd=xpd.orig) + } + else + warning("Invalid value for srtRow ignored.") + } + + + + ## add row and column headings (xlab, ylab) if(!is.null(xlab)) mtext(xlab, side = 1, line = margins[1] - 1.25) - axis(4, iy, labels= labRow, las= 2, line= -0.5, tick= 0, cex.axis= cexRow) if(!is.null(ylab)) mtext(ylab, side = 4, line = margins[2] - 1.25) ## perform user-specified function Modified: trunk/gplots/man/heatmap.2.Rd =================================================================== --- trunk/gplots/man/heatmap.2.Rd 2013-10-11 17:15:54 UTC (rev 1723) +++ trunk/gplots/man/heatmap.2.Rd 2013-10-11 20:19:22 UTC (rev 1724) @@ -64,6 +64,12 @@ cexCol = 0.2 + 1/log10(nc), labRow = NULL, labCol = NULL, + srtRow = NULL, + srtCol = NULL, + adjRow = c(0,NA), + adjCol = c(NA,0), + offsetRow = 0.5, + offsetCol = 0.5, # color key + density info key = TRUE, @@ -178,6 +184,12 @@ \item{labRow, labCol}{character vectors with row and column labels to use; these default to \code{rownames(x)} or \code{colnames(x)}, respectively.} + \item{srtRow, srtCol}{angle of row/column labels, in degrees from horizontal} + \item{adjRow, adjCol}{2-element vector giving the (left-right, + top-bottom) justification of row/column labels (relative to the text + orientation).} + \item{offsetRow, offsetCol}{Number of character-width spaces to place + between row/column labels and the edge of the plotting region.} % Color key and density info \item{key}{logical indicating whether a color-key should be shown.} \item{keysize}{numeric value indicating the size of the key} @@ -302,6 +314,33 @@ heatmap.2(x, Rowv=NULL, dendrogram="both") ## generate warning! heatmap.2(x, Colv=FALSE, dendrogram="both") ## generate warning! + ## Show effect of row and column label rotation + heatmap.2(x, srtCol=NULL) + heatmap.2(x, srtCol=0, adjCol = c(0.5,1) ) + heatmap.2(x, srtCol=45, adjCol = c(1,1) ) + heatmap.2(x, srtCol=135, adjCol = c(1,0) ) + heatmap.2(x, srtCol=180, adjCol = c(0.5,0) ) + heatmap.2(x, srtCol=225, adjCol = c(0,0) ) ## not very useful + heatmap.2(x, srtCol=270, adjCol = c(0,0.5) ) + heatmap.2(x, srtCol=315, adjCol = c(0,1) ) + heatmap.2(x, srtCol=360, adjCol = c(0.5,1) ) + + heatmap.2(x, srtRow=45, adjRow=c(0, 1) ) + heatmap.2(x, srtRow=45, adjRow=c(0, 1), srtCol=45, adjCol=c(1,1) ) + heatmap.2(x, srtRow=45, adjRow=c(0, 1), srtCol=270, adjCol=c(0,0.5) ) + + ## Show effect of offsetRow/offsetCol (only works when srtRow/srtCol is + ## not also present) + heatmap.2(x, offsetRow=0, offsetCol=0) + heatmap.2(x, offsetRow=1, offsetCol=1) + heatmap.2(x, offsetRow=2, offsetCol=2) + heatmap.2(x, offsetRow=-1, offsetCol=-1) + + heatmap.2(x, srtRow=0, srtCol=90, offsetRow=0, offsetCol=0) + heatmap.2(x, srtRow=0, srtCol=90, offsetRow=1, offsetCol=1) + heatmap.2(x, srtRow=0, srtCol=90, offsetRow=2, offsetCol=2) + heatmap.2(x, srtRow=0, srtCol=90, offsetRow=-1, offsetCol=-1) + ## ## Show effect of z-score scaling within columns, blue-red color scale ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |