[R] how to specify bin width in hist()
Jim Lemon
jim at bitwrit.com.au
Thu Oct 4 12:04:47 CEST 2007
Abu Naser wrote:
> Hi all user,
>
> I have been wondering how the bin width can be specified in hist().
Hi Abu,
If you want constant bin widths (e.g. from 0 to 10), it's easy:
my.bin.width<-2
hist(...,breaks=seq(0,10,by=my.bin.width),...)
and the "by" argument is your width. If you want completely customized
bin widths (which may not be a great idea):
my.bin.widths<-c(2,3,4,1)
hist(...,breaks=c(0,cumsum(my.bin.widths)),...)
also look at the right= argument to decide whether to include the lower
or higher break value in each bin.
Jim
More information about the R-help
mailing list