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: 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
Le 13.12.2005 19:34, S??rgio Nunes a ??crit :>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: > >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 > >Hi, You want to travel in the RGB space. See http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=107 plot(0, xlim=c(0,10), ylim=c(0,1)) pal <- rgb(1, 0:10/10,0:10/10) rect(xleft=0:9, xright=1:10, ytop=1, ybottom=0, col=pal) Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php +---------------------------------------------------------------+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---------------------------------------------------------------+
> 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
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)
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 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
Seemingly Similar Threads
- slow tint when tinting the whole screen
- Question: xyplot panel configurations for Trellis package
- [Bug 79266] New: (two) GT 430 / GF108 sluggish, unstable performance and blue tint with vdpau
- greyPalette() in legend plot
- filled contour plot with contour lines