I could not get Jim code to work (can't install colors in R 2.13). However Alexander code seems what I want. Just a litle detail, I need all bars with same size, the only difference between they are the colors.
On Thu, Jul 28, 2011 at 6:11 AM, Jim Lemon <j...@bitwrit.com.au> wrote: > 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 > -- Fernando Andreacci Biólogo Fone +55 47 9921 4015 +55 41 9921 3934 fandrea...@gmail.com -- Fernando Andreacci Biólogo Fone +55 47 9921 4015 +55 41 9921 3934 fandrea...@gmail.com [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.