# Why is the tick marker for zero after the bar in this qplot bar chart?

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

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

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

produces

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