Feature or bug? Why is it that the tick marker for zero projects is after the bar that represents the count for zero in this plot (instead of being in the middle as I'd have expected):

> qplot(projects,data=subset(df,projects<1000),geom="bar")
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this

enter image description here

Here is the data I am using:

      username gender   id   tenure  projects post
1      foo     male     123   1566      120   75
2      bar     male     456   1565       78    1
3      baz     female   678   1564       55    1

The reason it appears to the left is that it putting the $0$ projects into a bin $(-33,0]$ which it then treats as negative. To solve this you need right=FALSE. You could then have a similar problem at the other end with the $999$ projects put into the bin $[999,1032)$ which would appear above $1000$; so it would be better to have a binwidth which is a factor of $1000$ - I would suggest binwidth=25.

For example

df <- data.frame(projects = rgeom(10000,.005) )
qplot(projects, data=subset(df, projects<1000), geom="bar", 
       binwidth=25, right=FALSE )


enter image description here

  • $\begingroup$ what is set.seed for? $\endgroup$ – amh Jun 23 '11 at 15:28
  • $\begingroup$ @andresmh: so that if you run the script you get exactly the same result. If you want new random numbers then remove it. $\endgroup$ – Henry Jun 23 '11 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.