title: Histogram binwidth (in)consistency between base graphics and ggplot2
body: <p>I ran into the following scenario...</p>
  
  <p>The following code produce the 2 identical histogram:</p>
  
  <pre><code>library(ggplot2)
  data("diamonds")    
  ggplot(diamonds, aes(x=price)) + geom_histogram(binwidth=1000)
  qplot(price, data = diamonds, binwidth = 1000)
  </code></pre>
  
  <p>However, I do not understand how they derive the first bar/bin on the left, in fact, the whole histogram seems wrong to me.
  <a href="https://i.stack.imgur.com/Q9XLi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q9XLi.jpg" alt="enter image description here"></a></p>
  
  <p>On the other hand:</p>
  
  <pre><code>hist(diamonds$price,breaks = seq(0,20000, by=1000))
  </code></pre>
  
  <p>produces the following graph which seems right to me:
  <a href="https://i.stack.imgur.com/bOLV6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bOLV6.jpg" alt="enter image description here"></a></p>
  
  <p>To validate the data I ran this code:</p>
  
  <pre><code>br = seq(0,20000,by=1000)
  
  ranges = paste(head(br,-1), br[-1], sep=" - ")
  freq = hist(diamonds$price, breaks = br, include.lowest=TRUE, plot=FALSE)
  
  data.frame(range = ranges, frequency = freq$counts)
  </code></pre>
  
  <p>and it produces:</p>
  
  <pre><code>           range frequency
  1       0 - 1000     14524
  2    1000 - 2000      9683
  3    2000 - 3000      6129
  4    3000 - 4000      4225
  5    4000 - 5000      4665
  ...
  </code></pre>
  
  <p>So where does that first bar/bin in <code>ggplot</code> or <code>qplot</code> come from?</p>