Re: Ploting graphics using X tints from a color

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Open this post in threaded view
Report Content as Inappropriate

Re: Ploting graphics using X tints from a color

Roger Bivand
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
> ______________________________________________
> [hidden email] mailing list
> PLEASE do read the posting guide!

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: [hidden email]

[hidden email] mailing list
PLEASE do read the posting guide!
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway