I've got a data set with integer codes from 0--3. I'd like a histogram with a single bar for 0, 1, 2 and 3. I'd like each of the 4 bars centered over a label. hist(mydata, breaks=4, main="Simulation") gives me three bars. The best I've been able to do is do something like print(hist((wexp), breaks=25, main="Simulation")) This gives me something close to what I want, but seems like a silly way to do it. I'm about to give up and have someone do it in Excel (which peeves me to no end). To further complicate matters, one data set has no items in the zero cell. I'd like that graph to look like the others (using my stupid hack above it has bars that are a different width). Thanks. -- Jay Pfaffman pfaffman at relaxpc.com +1-415-821-7507 (H) +1-415-812-5047 (M)
Hi Sounds like a barplot may provide a more appropriate visualisation; see ?barplot Paul Jay Pfaffman wrote:> I've got a data set with integer codes from 0--3. I'd like a > histogram with a single bar for 0, 1, 2 and 3. I'd like each of the 4 > bars centered over a label. > > hist(mydata, breaks=4, main="Simulation") > > gives me three bars. The best I've been able to do is do something > like > > print(hist((wexp), breaks=25, main="Simulation")) > > This gives me something close to what I want, but seems like a silly > way to do it. I'm about to give up and have someone do it in Excel > (which peeves me to no end). > > To further complicate matters, one data set has no items in the zero > cell. I'd like that graph to look like the others (using my stupid > hack above it has bars that are a different width). > > Thanks. >-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
> hist(sample(0:3, 10, T), breaks=(0:4)-0.5)At Thursday 02:32 PM 7/17/2003 -0700, Jay Pfaffman wrote:>I've got a data set with integer codes from 0--3. I'd like a >histogram with a single bar for 0, 1, 2 and 3. I'd like each of the 4 >bars centered over a label. > > hist(mydata, breaks=4, main="Simulation") > >gives me three bars. The best I've been able to do is do something >like > > print(hist((wexp), breaks=25, main="Simulation")) > >This gives me something close to what I want, but seems like a silly >way to do it. I'm about to give up and have someone do it in Excel >(which peeves me to no end). > >To further complicate matters, one data set has no items in the zero >cell. I'd like that graph to look like the others (using my stupid >hack above it has bars that are a different width). > >Thanks. > >-- >Jay Pfaffman pfaffman at relaxpc.com >+1-415-821-7507 (H) +1-415-812-5047 (M) > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Jay Pfaffman <pfaffman at relaxpc.com> wrote: I've got a data set with integer codes from 0--3. I'd like a histogram with a single bar for 0, 1, 2 and 3. I'd like each of the 4 bars centered over a label.> x <- rbinom(100, 3, 0.5) > barplot(table(x))This returns a vector of bar locations, which you can use to place your labels.