[R] colorRamp

From: Rick Bischoff <rdbisch_at_gmail.com>
Date: Tue 05 Sep 2006 - 04:27:03 GMT


Hi,

I am using colorRamp in the following way. I am *sure* there is a better way to do this, so if you'd be so kind to show me the true R way:

Step 0: Create a new variable, say, "x", that maps some other continuous variable I have onto the [0,1] line. Step 1: Store the result from colorRamp (a function), into, say, "test"

> test <- colorRamp(mypalette)

Step 2: In my data frame, "data"

> data$colorTemp <- test(data$x)

Step 3: Write a new function

bob <- function(temp) { rgb(temp[1],temp[2],temp[3],maxColorValue=255) }

Step 4:

> for (i in 1:dim(data)[1]) data[i,"color"] <- bob(data[i,
"colorTemp"])

Step 5:

map("states", region=data$region, fill=T, col=data$color)

Thanks in advance!
Rick



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue Sep 05 14:45:06 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.