[R] Removing inter-bar spaces in barchart

Jonathan Greenberg greenberg at ucdavis.edu
Thu Aug 26 01:46:40 CEST 2010


I apologize, let me add some data to play with:

barchart_test_heights=sin(c(1:100))
barchart_test_bins=c(1:100)
groups=c(rep(1,50),rep(2,50))

I have pre-calculated histogram data and the bins they belong to.  I
would like to plot the two histograms superimposed on one-another,
having group 1 bars for a given bin be next to group 2 bars, something
along the lines of:

barchart(barchart_test_bins~barchart_test_heights,groups=groups)

except with no space between the bars (and a key for the groups).

--j

P.S. And yes I was talking about barchart() from lattice -- however, I
am happy to use another function if that makes this easier.

On Wed, Aug 25, 2010 at 1:55 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Aug 24, 2010, at 10:20 PM, Jonathan Greenberg wrote:
>
>> Rhelpers:
>>
>> I'm trying to make a barchart of a 2-group dataset
>> (barchart(x~y,data=data,groups=z,horizontal=FALSE)).  My problem is
>> that I can't, for the life of me, seem to get rid of the inter-bar
>> space -- box.ratio set to 10000 doesn't do much.  Any ideas?  I'd
>> ideally want zero space between the bars.  Thanks!
>
> You didn't provide any data (nor did you illustrate with one of the
> available datasets that are used in examples.)
>
> Compare these two outputs:
>
> barchart(yield ~ year, data = barley,
>         groups = variety,   ylab = "Barley Yield (bushels/acre)",
>        )
>
> barchart(yield ~ variety, data = barley,
>         groups = year,   ylab = "Barley Yield (bushels/acre)",
>        )
>
> ... and notice that the variables in the "group" have no separation of their
> bars whereas the rhs variables do. This is the opposite of what I expected,
> so perhaps you think as I did and reversing the roles of"y" and "z"  might
> help?
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
>



-- 
Jonathan A. Greenberg, PhD
Assistant Project Scientist
Center for Spatial Technologies and Remote Sensing (CSTARS)
Department of Land, Air and Water Resources
University of California, Davis
One Shields Avenue
Davis, CA 95616
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307



More information about the R-help mailing list