6
$\begingroup$

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 
$\endgroup$

1 Answer 1

8
$\begingroup$

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

enter image description here

$\endgroup$
2
  • $\begingroup$ what is set.seed for? $\endgroup$ Commented Jun 23, 2011 at 15:28
  • 1
    $\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$ Commented Jun 23, 2011 at 21:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.