[R] barplot - offsetting individual bars

Jim Lemon jim at bitwrit.com.au
Sun Apr 25 06:01:34 CEST 2010


On 04/25/2010 05:04 AM, Kevin Turner wrote:
> Hello,
>
> I'm trying currently using barplot to summarize precipitation data.  So far
> I've compiled total annual snow and rain accumulation in a table
> (attached).  I've been successful at plotting it using the following code:
>
> fig=barplot(t(Annual_Precip_table), horiz=TRUE, space=0, col=c("grey70",
> "white"), axes=FALSE)
> .
> .
> The result is a stacked barplot with total annual rain represented by grey
> bars and total annual snow represented by white bars.  This is great,
> however, I'd like to position the bars so that the rain bars are right
> justified on the axis and the snow bars are left justified on the axis.
>
> I looked around for ways to do this, and I'm not sure, but is plotrix
> capable of doing it using the barb function?  Does anyone have experience
> with this kind of plot?
>
Hi Kevin,
No, barp can't do this, but you may have to program a custom plot using 
similar code. barp creates an empty plot and then draws rectangles on 
it. It wouldn't be too hard to stack your rectangles from the left or 
right depending upon a test of whether the stack represented rain or 
snow. I haven't encountered this type of plot before, but if it is 
common in some area, it might be worth writing a proper function and 
making it available to others who could use it.

Jim



More information about the R-help mailing list