[R-gregmisc-users] SF.net SVN: r-gregmisc:[1930] trunk/gplots
Brought to you by:
warnes
From: <wa...@us...> - 2015-04-22 21:33:14
|
Revision: 1930 http://sourceforge.net/p/r-gregmisc/code/1930 Author: warnes Date: 2015-04-22 21:33:06 +0000 (Wed, 22 Apr 2015) Log Message: ----------- heatmap.2: add new 'colRow' and 'colCol' arguments to control the color of row and column text labels 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 2015-04-14 22:02:42 UTC (rev 1929) +++ trunk/gplots/R/heatmap.2.R 2015-04-22 21:33:06 UTC (rev 1930) @@ -59,6 +59,8 @@ adjCol = c(NA,0), offsetRow = 0.5, offsetCol = 0.5, + colRow = NULL, + colCol = NULL, ## color key + density info key = TRUE, @@ -281,6 +283,12 @@ labCol <- if(is.null(colnames(x))) (1:nc)[colInd] else colnames(x) else labCol <- labCol[colInd] + + if(!is.null(colRow)) + colRow <- colRow[rowInd] + + if(!is.null(colCol)) + colCol <- colCol[colInd] if(scale == "row") { retval$rowMeans <- rm <- rowMeans(x, na.rm = na.rm) @@ -415,7 +423,7 @@ } ## add column labels - if(is.null(srtCol)) + if(is.null(srtCol) && is.null(colCol)) axis(1, 1:nc, labels= labCol, @@ -428,7 +436,7 @@ ) else { - if(is.numeric(srtCol)) + if(is.null(srtCol) || is.numeric(srtCol)) { if(missing(adjCol) || is.null(adjCol)) adjCol=c(1,NA) @@ -442,7 +450,10 @@ ##pos=1, adj=adjCol, cex=cexCol, - srt=srtCol) + srt=srtCol, + col=colCol + ) + print(colCol) par(xpd=xpd.orig) } else @@ -450,7 +461,7 @@ } ## add row labels - if(is.null(srtRow)) + if(is.null(srtRow) && is.null(colRow)) { axis(4, iy, @@ -465,7 +476,7 @@ } else { - if(is.numeric(srtRow)) + if(is.null(srtRow) || is.numeric(srtRow)) { xpd.orig <- par("xpd") par(xpd=NA) @@ -475,7 +486,8 @@ labels=labRow, adj=adjRow, cex=cexRow, - srt=srtRow + srt=srtRow, + col=colRow ) par(xpd=xpd.orig) } Modified: trunk/gplots/man/heatmap.2.Rd =================================================================== --- trunk/gplots/man/heatmap.2.Rd 2015-04-14 22:02:42 UTC (rev 1929) +++ trunk/gplots/man/heatmap.2.Rd 2015-04-22 21:33:06 UTC (rev 1930) @@ -71,6 +71,8 @@ adjCol = c(NA,0), offsetRow = 0.5, offsetCol = 0.5, + colRow = NULL, + colCol = NULL, # color key + density info key = TRUE, @@ -111,10 +113,11 @@ \code{\link{dendrogram}}, then it is used "as-is", ie without any reordering. If a vector of integers, then dendrogram is computed and reordered based on the order of the vector.} - \item{Colv}{determines if and how the \emph{column} dendrogram should be - reordered. Has the options as the \code{Rowv} argument above and - \emph{additionally} when \code{x} is a square matrix, \code{Colv = - "Rowv"} means that columns should be treated identically to the rows.} + \item{Colv}{determines if and how the \emph{column} dendrogram should + be reordered. Has the options as the \code{Rowv} argument above and + \emph{additionally} when \code{x} is a square matrix, + \code{Colv="Rowv"} means that columns should be treated identically + to the rows.} \item{distfun}{function used to compute the distance (dissimilarity) between both rows and columns. Defaults to \code{\link{dist}}.} \item{hclustfun}{function used to compute the hierarchical clustering @@ -128,7 +131,8 @@ reordering the row and column dendrograms. The default uses \code{\link{stats}{reorder.dendrogram}} }. \item{symm}{logical indicating if \code{x} should be treated - \bold{symm}etrically; can only be true when \code{x} is a square matrix.} + \bold{symm}etrically; can only be true when \code{x} is a + square matrix.} % data scaling \item{scale}{character indicating if the values should be centered and scaled in either the row direction or the column direction, or @@ -150,12 +154,14 @@ \item{col}{colors used for the image. Defaults to heat colors (\code{heat.colors}).} % block separation - \item{colsep, rowsep, sepcolor}{(optional) vector of integers indicating - which columns or rows should be separated from the preceding columns - or rows by a narrow space of color \code{sepcolor}.} - \item{sepwidth}{(optional) Vector of length 2 giving the width (colsep) or height (rowsep) the separator box - drawn by colsep and rowsep as a function of the width (colsep) or - height (rowsep) of a cell. Defaults to \code{c(0.05, 0.05)}} + \item{colsep, rowsep, sepcolor}{(optional) vector of integers + indicating which columns or rows should be separated from the + preceding columns or rows by a narrow space of color + \code{sepcolor}.} + \item{sepwidth}{(optional) Vector of length 2 giving the width + (colsep) or height (rowsep) the separator box drawn by colsep and + rowsep as a function of the width (colsep) or height (rowsep) of a + cell. Defaults to \code{c(0.05, 0.05)}} % cell labeling \item{cellnote}{(optional) matrix of character strings which will be placed within each color cell, e.g. p-value symbols.} @@ -181,25 +187,31 @@ defaults to the value of \code{tracecol}.} % Row/Column Labeling \item{margins}{numeric vector of length 2 containing the margins - (see \code{\link{par}(mar= *)}) for column and row names, respectively.} - \item{ColSideColors}{(optional) character vector of length \code{ncol(x)} - containing the color names for a horizontal side bar that may be used to - annotate the columns of \code{x}.} - \item{RowSideColors}{(optional) character vector of length \code{nrow(x)} - containing the color names for a vertical side bar that may be used to - annotate the rows of \code{x}.} + (see \code{\link{par}(mar= *)}) for column and row names, + respectively.} + \item{ColSideColors}{(optional) character vector of length + \code{ncol(x)} containing the color names for a horizontal side bar + that may be used to annotate the columns of \code{x}.} + \item{RowSideColors}{(optional) character vector of length + \code{nrow(x)} containing the color names for a vertical side bar + that may be used to annotate the rows of \code{x}.} \item{cexRow, cexCol}{positive numbers, used as \code{cex.axis} in for the row or column axis labeling. The defaults currently only use number of rows or columns, respectively.} \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{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.} + orientation).} + \item{offsetRow, offsetCol}{Number of character-width spaces to + place between row/column labels and the edge of the plotting + region.} + \item{colRow, colCol}{color of row/column labels, either a scalar to + set the color of all labels the same, or a vector providing the + colors of each label item} % 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} @@ -226,8 +238,8 @@ the xaxis of the color key. Returns a named list containing parameters that can be passed to \code{axis}. See examples.} \item{key.ytickfun}{function computing tick location and labels for - the y axis of the color key. Returns a named list containing - parameters that can be passed to \code{axis}. See examples.} + the y axis of the color key. Returns a named list containing + parameters that can be passed to \code{axis}. See examples.} \item{key.par}{graphical parameters for the color key. Named list that can be passed to \code{par}.} % plot labels @@ -446,14 +458,19 @@ RowSideColors=rc, ColSideColors=cc, margin=c(5, 10), xlab="specification variables", ylab= "Car Models", main="heatmap(<Mtcars data>, ..., scale=\"column\")", - tracecol="green", density="density") + tracecol="green", density="density") ## Note that the breakpoints are now symmetric about 0 + + ## Color the labels to match RowSideColors and ColSideColors + hv <- heatmap.2(x, col=cm.colors(255), scale="column", + RowSideColors=rc, ColSideColors=cc, margin=c(5, 10), + xlab="specification variables", ylab= "Car Models", + main="heatmap(<Mtcars data>, ..., scale=\"column\")", + tracecol="green", density="density", colRow=rc, colCol=cc, + srtCol=45, adjCol=c(0.5,1)) + - - - - %% want example using the `add.exp' argument! data(attitude) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |