Re: [R] Ploting graphics using X tints from a color

From: Roger Bivand <Roger.Bivand_at_nhh.no>
Date: Wed 14 Dec 2005 - 18:58:34 EST


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:

library(RColorBrewer)
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@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@nhh.no

______________________________________________
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
Received on Wed Dec 14 19:04:14 2005

This archive was generated by hypermail 2.1.8 : Wed 14 Dec 2005 - 20:25:53 EST