[R] Ploting graphics using X tints from a color

Roger Bivand Roger.Bivand at nhh.no
Wed Dec 14 08:58:34 CET 2005

On Tue, 13 Dec 2005, Sérgio Nunes wrote:

> Hi,
> I'm trying to draw a 2D plot using multiple tints of red. The
> (simplified) setup is the following: || year | x | y ||
> My idea is that each year is plotted with a different tint of red.
> Older year (lightest) -> Later year (darkest). I've managed to plot
> this with different scales of grays simply by doing:

There have been other replies using rgb and hsv colour spaces directly,
but the new colorRamp and colorRampPalette functions iare worth mentioning
because they pack those solutions into a general framework:

years <- 1:20
plot(years, pch=19, col=grey(length(years):0/length(years)))

redPalette <- colorRampPalette(c("white", "red"))
plot(years, pch=19, col=redPalette(length(years)))

and the grey values can be reconstructed by:

greyPalette <- colorRampPalette(c("white", "black"))
plot(years, pch=19, col=greyPalette(length(years)))

with some values differing by 1 RGB unit. I've found colorRampPalette() 
very flexible, and that it supplements RColorBrewer well, so that 
intermediate colours can be interpolated for those palettes:

redPalette <- colorRampPalette(brewer.pal(5, "Reds"))
plot(years, pch=19, col=redPalette(length(years)))

for a touch more tomato (subjectively) in the red.

> palette(gray(length(years):0/length(years)))
> before the plot and for each year the color used is a different tint of gray.
> So, is there any way to do this for any color?
> Any tip or advice?
> With this, I hope to visualize patterns in my dataset more easily.
> Thanks in advance for any help.
> Best regards,
> Sérgio Nunes
> ______________________________________________
> R-help at 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

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

More information about the R-help mailing list