Skip to content

Ploting gradient

5 messages · Alexander Engelhardt, Jim Lemon, Fernando Andreacci

#
Am 28.07.2011 03:25, schrieb Fernando Andreacci:
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
#
On 07/28/2011 11:25 AM, Fernando Andreacci wrote:
Hi Fernando,
I think you want the grayscale to reflect the values of the percentages, 
so here is one way to do it:

# make up some values for the bars
barvalues<-sample(0:9,10)
# make up some values for the percentages
pctvalues<-sample(0:100,10)
# draw a barplot
xpos<-barplot(barvalues,ylim=c(0,10))
# translate the percent values into grayscale
pctcolors<-color.scale(pctvalues)
rect(xpos-0.3,barvalues+0.5,xpos+0.3,barvalues+1,col=pctcolors)

Jim