[R-gregmisc-users] SF.net SVN: r-gregmisc:[1372] trunk/gplots
Brought to you by:
warnes
From: <ar...@us...> - 2010-01-22 13:56:10
|
Revision: 1372 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1372&view=rev Author: arnima Date: 2010-01-22 13:55:22 +0000 (Fri, 22 Jan 2010) Log Message: ----------- Renamed files rich.color.* to rich.colors.* and renamed rich.colors args Added Paths: ----------- trunk/gplots/R/rich.colors.R trunk/gplots/man/rich.colors.Rd Removed Paths: ------------- trunk/gplots/R/rich.color.R trunk/gplots/man/rich.color.Rd Deleted: trunk/gplots/R/rich.color.R =================================================================== --- trunk/gplots/R/rich.color.R 2010-01-22 13:06:33 UTC (rev 1371) +++ trunk/gplots/R/rich.color.R 2010-01-22 13:55:22 UTC (rev 1372) @@ -1,50 +0,0 @@ -rich.colors <- function(n, palette="temperature", rgb.matrix=FALSE, - plot.colors=FALSE) -{ - if(n <= 0) - return(character(0)) - - palette <- match.arg(palette, c("temperature","blues")) - x <- seq(0, 1, length=n) - - if(palette == "temperature") - { - r <- 1 / (1+exp(20-35*x)) - g <- pmin(pmax(0,-0.8+6*x-5*x^2), 1) - b <- dnorm(x,0.25,0.15) / max(dnorm(x,0.25,0.15)) - } - else - { - r <- 0.6*x + 0.4*x^2 - g <- 1.5*x - 0.5*x^2 - b <- 0.36 + 2.4*x - 2.0*x^2 - 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])) - - if(rgb.matrix) - attr(rich.vector, "rgb.matrix") <- rgb.m - - if(plot.colors) - { - opar <- par("fig", "plt") - par(fig=c(0,1,0,0.7), plt=c(0.15,0.9,0.2,0.95)) - plot(NA, xlim=c(-0.01,1.01), ylim=c(-0.01,1.01), xlab="Spectrum", ylab="", - xaxs="i", yaxs="i", axes=FALSE) - title(ylab="Value", mgp=c(3.5,0,0)) - matlines(x, rgb.m, col=colnames(rgb.m), lty=1, lwd=3) - matpoints(x, rgb.m, col=colnames(rgb.m), pch=16) - 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, - axes=FALSE) - axis(1, at=midpoints, labels=1:n, lty=0, cex.axis=0.6) - par(opar) - } - return(rich.vector) -} Copied: trunk/gplots/R/rich.colors.R (from rev 1371, trunk/gplots/R/rich.color.R) =================================================================== --- trunk/gplots/R/rich.colors.R (rev 0) +++ trunk/gplots/R/rich.colors.R 2010-01-22 13:55:22 UTC (rev 1372) @@ -0,0 +1,49 @@ +rich.colors <- function(n, palette="temperature", rgb=FALSE, plot=FALSE) +{ + if(n <= 0) + return(character(0)) + + palette <- match.arg(palette, c("temperature","blues")) + x <- seq(0, 1, length=n) + + if(palette == "temperature") + { + r <- 1 / (1+exp(20-35*x)) + g <- pmin(pmax(0,-0.8+6*x-5*x^2), 1) + b <- dnorm(x,0.25,0.15) / max(dnorm(x,0.25,0.15)) + } + else + { + r <- 0.6*x + 0.4*x^2 + g <- 1.5*x - 0.5*x^2 + b <- 0.36 + 2.4*x - 2.0*x^2 + 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])) + + if(rgb) + attr(rich.vector, "rgb") <- rgb.m + + if(plot) + { + opar <- par("fig", "plt") + par(fig=c(0,1,0,0.7), plt=c(0.15,0.9,0.2,0.95)) + plot(NA, xlim=c(-0.01,1.01), ylim=c(-0.01,1.01), xlab="Spectrum", ylab="", + xaxs="i", yaxs="i", axes=FALSE) + title(ylab="Value", mgp=c(3.5,0,0)) + matlines(x, rgb.m, col=colnames(rgb.m), lty=1, lwd=3) + matpoints(x, rgb.m, col=colnames(rgb.m), pch=16) + 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, + axes=FALSE) + axis(1, at=midpoints, labels=1:n, lty=0, cex.axis=0.6) + par(opar) + } + return(rich.vector) +} Deleted: trunk/gplots/man/rich.color.Rd =================================================================== --- trunk/gplots/man/rich.color.Rd 2010-01-22 13:06:33 UTC (rev 1371) +++ trunk/gplots/man/rich.color.Rd 2010-01-22 13:55:22 UTC (rev 1372) @@ -1,53 +0,0 @@ -\name{rich.colors} -\alias{rich.colors} -\title{ - Rich color palettes -} -\description{ - Create a vector of \code{n} colors that are perceptually equidistant - and in an order that is easy to interpret. -} -\usage{ -rich.colors(n, palette="temperature", rgb.matrix=FALSE, - plot.colors=FALSE) -} -\arguments{ - \item{n}{number of colors to generate.} - \item{palette}{palette to use: \code{"temperature"} contains - blue-green-yellow-red, and \code{"blues"} contains - black-blue-white.} - \item{rgb.matrix}{if \code{TRUE} then a matrix of RGB values is - included as an attribute.} - \item{plot.colors}{if \code{TRUE} then a descriptive color diagram is - plotted on the current device.} -} -\value{ - A character vector of color codes. -} -\author{Arni Magnusson \email{arnima@u.washington.edu}} -\seealso{ - \code{\link{rgb}}, - \code{\link{rainbow}}, - \code{\link{heat.colors}}. -} -\examples{ -m <- 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")) -par(opar) - -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 - -par(mfrow=c(2,2)) -barplot(m, col=heat.colors(15), main="\nheat.colors") -barplot(m, col=1:15, main="\ndefault palette") -barplot(m, col=rich.colors(15), main="\nrich.colors") -barplot(m, col=rainbow(15), main="\nrainbow") -par(opar) -} -% Graphics -\keyword{color} Copied: trunk/gplots/man/rich.colors.Rd (from rev 1371, trunk/gplots/man/rich.color.Rd) =================================================================== --- trunk/gplots/man/rich.colors.Rd (rev 0) +++ trunk/gplots/man/rich.colors.Rd 2010-01-22 13:55:22 UTC (rev 1372) @@ -0,0 +1,46 @@ +\name{rich.colors} +\alias{rich.colors} +\title{Rich Color Palettes} +\description{ + Create a vector of \code{n} colors that are perceptually equidistant + and in an order that is easy to interpret. +} +\usage{ +rich.colors(n, palette="temperature", rgb=FALSE, plot=FALSE) +} +\arguments{ + \item{n}{number of colors to generate.} + \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.} +} +\value{A character vector of color codes.} +\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) +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")) +par(opar) + +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 + +par(mfrow=c(2,2)) +barplot(m, col=heat.colors(15), main="\nheat.colors") +barplot(m, col=1:15, main="\ndefault palette") +barplot(m, col=rich.colors(15), main="\nrich.colors") +barplot(m, col=rainbow(15), main="\nrainbow") +par(opar) +} +% Graphics +\keyword{color} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |