[R] barplot - offsetting individual bars

Greg Snow Greg.Snow at imail.org
Mon Apr 26 21:49:14 CEST 2010


Does this do what you want?

rainsnow <- rbind( c(0,1,2,3,2,1,0), c(2,2,1,0,0,1,2) )

rainsnow2 <- rbind( rainsnow[1,], -rainsnow[1,], -rainsnow[2,] )

fig=barplot(rainsnow2, horiz=TRUE, space=0, col=c("grey70",NA,
"white"), axes=FALSE)

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Kevin Turner
> Sent: Saturday, April 24, 2010 1:04 PM
> To: r-help at r-project.org
> Subject: [R] barplot - offsetting individual bars
> 
> 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?
> 
> Thanks.
> 
> --
> Kevin Turner
> Department of Geography
> and Environmental Studies
> Wilfrid Laurier University
> Waterloo, Ontario



More information about the R-help mailing list