[R] histogram first bar wrong position
itpro
itpro1 at yandex.ru
Thu Dec 22 14:17:28 CET 2016
Hi, everyone.
I stumbled upon weird histogram behaviour.
Consider this "dice emulator":
Step 1: Generate uniform random array x of size N.
Step 2: Multiply each item by six and round to next bigger integer to get numbers 1 to 6.
Step 3: Plot histogram.
> x<-runif(N)
> y<-ceiling(x*6)
> hist(y,freq=TRUE, col='orange')
Now what I get with N=100000
> x<-runif(100000)
> y<-ceiling(x*6)
> hist(y,freq=TRUE, col='green')
At first glance looks OK.
Now try N=100
> x<-runif(100)
> y<-ceiling(x*6)
> hist(y,freq=TRUE, col='red')
Now first bar is not where it should be.
Hmm. Look again to 100000 histogram... First bar is not where I want it, it's only less striking due to narrow bars.
So, first bar is always in wrong position. How do I fix it to make perfectly spaced bars?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: r100.png
Type: image/png
Size: 21541 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161222/174d507d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: r100000.png
Type: image/png
Size: 22247 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161222/174d507d/attachment-0001.png>
More information about the R-help
mailing list