[R] Ploting gradient

Alexander Engelhardt alex at chaotic-neutral.de
Thu Jul 28 08:44:11 CEST 2011


Am 28.07.2011 03:25, schrieb Fernando Andreacci:
> I have a simple bar chart with annual precipitation (jan to dez).
>
> I want to plot, above each bar (on a line), a square wich is color based on
> a scale (0-100%). With 0 being white and 100 black, like a gradient. Is it
> possible? How to?
> Thanks
>

Hey,
this good?

hex <- function(dec){
   stopifnot(round(dec)==dec && dec >= 0 && dec <= 100) # error checking 
line
   dec <- round(dec * 2.55) # scale 0-100 to 0-255
   class(dec) <- "hexmode" # transform to hex
   dec <- format(dec, width=2) # convert e.g. "3" to "03"

   paste("#", dec, dec, dec, sep="") # generate a #RRGGBB code, e.g. #030303
}

plot(1:11, col=hex(seq(0,100,by=10)))


Have fun,
  Alex



More information about the R-help mailing list