tags:

views:

91

answers:

4

This histogram is really ugly:

hist(rbinom(10000, 20000, 0.0001),freq=F,right=F)

I don't want spaces between my bars. I tried different breaks= methods but they all produce similar results. Any ideas?

I also want each bin value (or mean values )to be printed under the center of it's bar.

A: 

if the values are integer and simply you want to count up them, how about

barplot(table(rbinom(10000, 20000, 0.0001)))
kohske
that's good for some cases, but sometimes you'd really want the values to be binned together
David B
+1  A: 

In such a case I usually use:

 hist(rbinom(1000,2000,0.0001),breaks=function(x) length(unique(x)))
mbq
+1 thanks, that solves the first part. any suggestions on how to make the x labels centered?
David B
@David Try rcs's solution.
mbq
+1  A: 

Here is a way to center the labels:

x <- rbinom(1000, 2000, 0.001)
tmp <- hist(x, breaks=0:(max(x)+1), xaxt="n", right=FALSE, freq=FALSE)
axis(1, at=tmp$mids, labels=0:max(x))
rcs
+1 nice and simple, although the `breaks=0:(max(x)+1)` is not generic enough (in some cases you would like binning and not a bar for each int)
David B
This was just an example, it could be easily replaced by an appropriate `seq` statement.
rcs
A: 

Also:

x <- rbinom(10000, 20000, 0.0001)
hist(x, br = seq(-0.01, max(x)+1, 1), freq=F, col="black")

(the col="black" is not necessary, of course, I just find it more readeable in black!)

nico