[R] Ploting gradient

Jim Lemon jim at bitwrit.com.au
Thu Jul 28 11:11:05 CEST 2011


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



More information about the R-help mailing list