[R] Ploting graphics using X tints from a color

Ben Bolker bolker at ufl.edu
Tue Dec 13 22:14:31 CET 2005


SÃ©rgio Nunes <snunes <at> gmail.com> writes:

> 
> 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). 

 how about:

x = runif(300)
y = runif(300)
year = factor(rep(1:30,each=10))

nyear = length(levels(year))
grays = gray((nyear:0)/nyear)
reds = hsv(h=1,s=(0:nyear)/nyear,v=1)

plot(x,y,col=grays[as.numeric(year)],pch=16)
plot(x,y,col=reds[as.numeric(year)],pch=16)

plot(x,y,bg=reds[as.numeric(year)],pch=21,fg=1)
legend(0.8,1,levels(year),pch=21,pt.bg=reds,col=1,bg="white",ncol=2)




More information about the R-help mailing list