I'm using following code to plot histogram from discrete values:
vect=c(1,1,2,3,4,5,5,1)
h1=hist(vect, breaks=1:max(vect), right=FALSE)
The output of this is following:
My goal is to have bins separated as it is in following post. I've also tried to apply the code from mentioned post:
vect=c(1,1,2,3,4,5,5,1)
h1=hist(vect, breaks=1:rep(vect,each=2)+c(-.4,.4), right=FALSE)
but it gives an error. 2nd attempt was following code suggested by @TheTime:
vect=c(1,1,2,3,4,5,5,1)
h1=hist(vect, breaks=rep(1:max(vect),each=2)+c(-.4,.4), right=FALSE)
This returned:
As you can see there are some weird numbers 1 has value 1.6, 2 has value 1.4 etc.
> h1$breaks
[1] 0.6 1.4 1.6 2.4 2.6 3.4 3.6 4.4 4.6 5.4
What I'm doing wrong?