> I'm trying to draw a 2D plot using multiple tints of red. The
> (simplified) setup is the following: || year | x | y ||

You might find this function useful:

map_colour_gradient <- function(x, low="red",
mid="white",high="black", midpoint = 0) {
        x <- as.numeric(x)
        low.rgb <- col2rgb(low, TRUE)/256
        mid.rgb <- col2rgb(mid, TRUE)/256
        high.rgb <- col2rgb(high, TRUE)/256

        interp_r <- approxfun(c(min(x, na.rm=TRUE), midpoint, max(x,
na.rm=TRUE)), c(low.rgb[1], mid.rgb[1], high.rgb[1]))
        interp_g <- approxfun(c(min(x, na.rm=TRUE), midpoint, max(x,
na.rm=TRUE)), c(low.rgb[2], mid.rgb[2], high.rgb[2]))
        interp_b <- approxfun(c(min(x, na.rm=TRUE), midpoint, max(x,
na.rm=TRUE)), c(low.rgb[3], mid.rgb[3], high.rgb[3]))

        
        rgb(interp_r(x), interp_g(x), interp_b(x))
}

Given a numeric vector x, it will create a smooth gradient (linearly
through RGB space).

eg.

x <- rnorm(100)
y <- rnorm(100)

plot(x, y, col=map_colour_gradient(x), pch=20)
plot(x, y, col=map_colour_gradient(x, low="black", high="black",
mid="yellow"), pch=20)

Note, however, using colour is only likely to find the most prominent
of patterns.

Hadley

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to