In R, I can easily generate a color ramp, for example colorRampPalette. The following produces a sequence of five colors, from blue to red:
> mypal <- colo
The simplest thing I can think of is discretizing your variable x with cut
and then using the resultant factor to index a color Palettes like heat.colors
or cm.colors
f <- function(x,n=10){
heat.colors(n)[cut(x,n)]
}
see ?heat.colors
for more details of Palettes.
This function will give you are color vector corresponding to x
of varying granularity proportional to n
.