An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110727/86b6b0ad/attachment.pl>
Ploting gradient
5 messages · Alexander Engelhardt, Jim Lemon, Fernando Andreacci
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
On 07/28/2011 11:25 AM, Fernando Andreacci wrote:
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?
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110728/f386b07b/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110728/3f400d29/attachment.pl>