[R-gregmisc-users] SF.net SVN: r-gregmisc:[1470] trunk/gplots
Brought to you by:
warnes
From: <ar...@us...> - 2011-05-02 14:02:40
|
Revision: 1470 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1470&view=rev Author: arnima Date: 2011-05-02 14:02:34 +0000 (Mon, 02 May 2011) Log Message: ----------- Added argument 'alpha' and removed argument 'rgb' in rich.colors() Modified Paths: -------------- trunk/gplots/R/rich.colors.R trunk/gplots/man/rich.colors.Rd Modified: trunk/gplots/R/rich.colors.R =================================================================== --- trunk/gplots/R/rich.colors.R 2011-04-16 17:04:06 UTC (rev 1469) +++ trunk/gplots/R/rich.colors.R 2011-05-02 14:02:34 UTC (rev 1470) @@ -1,4 +1,4 @@ -rich.colors <- function(n, palette="temperature", rgb=FALSE, plot=FALSE) +rich.colors <- function(n, palette="temperature", alpha=1, plot=FALSE) { if(n <= 0) return(character(0)) @@ -20,14 +20,9 @@ b[x>0.4] <- 1 } - rgb.m <- matrix(c(r,g,b), ncol=3, - dimnames=list(as.character(seq(length=n)), - c("red","green","blue"))) - rich.vector <- apply(rgb.m, 1, function(v) rgb(v[1],v[2],v[3])) + rgb.m <- matrix(c(r,g,b), ncol=3, dimnames=list(NULL,c("red","green","blue"))) + col <- mapply(rgb, r, g, b, alpha) - if(rgb) - attr(rich.vector, "rgb") <- rgb.m - if(plot) { opar <- par("fig", "plt") @@ -40,10 +35,11 @@ axis(1, at=0:1) axis(2, at=0:1, las=1) par(fig=c(0,1,0.75,0.9), plt=c(0.08,0.97,0,1), new=TRUE) - midpoints <- barplot(rep(1,n), col=rich.vector, border=FALSE, space=FALSE, + midpoints <- barplot(rep(1,n), col=col, border=FALSE, space=FALSE, axes=FALSE) axis(1, at=midpoints, labels=1:n, lty=0, cex.axis=0.6) par(opar) } - return(rich.vector) + + return(col) } Modified: trunk/gplots/man/rich.colors.Rd =================================================================== --- trunk/gplots/man/rich.colors.Rd 2011-04-16 17:04:06 UTC (rev 1469) +++ trunk/gplots/man/rich.colors.Rd 2011-05-02 14:02:34 UTC (rev 1470) @@ -13,18 +13,16 @@ \item{palette}{palette to use: \code{"temperature"} contains blue-green-yellow-red, and \code{"blues"} contains black-blue-white.} - \item{rgb}{if \code{TRUE} then a matrix of RGB values is included as - an attribute.} - \item{plot}{if \code{TRUE} then a descriptive color diagram is plotted - on the current device.} + \item{alpha}{alpha transparency, from 0 to 1.} + \item{plot}{whether to plot a descriptive color diagram.} } \value{A character vector of color codes.} -\author{Arni Magnusson} +\author{Arni Magnusson.} \seealso{ \code{\link{rgb}}, \code{\link{rainbow}}, \code{\link{heat.colors}}. } \examples{ -m <- matrix(1:120+rnorm(120), nrow=15, ncol=8) +m <- abs(matrix(1:120+rnorm(120), nrow=15, ncol=8)) opar <- par(bg="gray", mfrow=c(1,2)) matplot(m, type="l", lty=1, lwd=3, col=rich.colors(8)) matplot(m, type="l", lty=1, lwd=3, col=rich.colors(8,"blues")) @@ -33,8 +31,11 @@ barplot(rep(1,100), col=rich.colors(100), space=0, border=0, axes=FALSE) barplot(rep(1,20), col=rich.colors(40)[11:30]) # choose subset -rich.colors(100, plot=TRUE, rgb=TRUE) # describe rgb recipe +plot(m, rev(m), ylim=c(120,0), pch=16, cex=2, + col=rich.colors(200,"blues",alpha=0.6)[1:120]) # semitransparent +rich.colors(100, plot=TRUE) # describe rgb recipe + par(mfrow=c(2,2)) barplot(m, col=heat.colors(15), main="\nheat.colors") barplot(m, col=1:15, main="\ndefault palette") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |