title: Align barplot with boxplot in R
body: <p>I would like to plot a distribution of counts using the barplot function in R, and underlay it with a boxplot to include information on median, quartiles, and outliers. A not-too-elegant solution for this has been found for histogram and boxplots: <a href="http://rgraphgallery.blogspot.com/2013/04/rg-plotting-boxplot-and-histogram.html" rel="nofollow">http://rgraphgallery.blogspot.com/2013/04/rg-plotting-boxplot-and-histogram.html</a>. </p>
  
  <p>There are many places online where one can find the argument being made that numerical data should be plotted with histograms while categorical data should be plotted with bar plots. My data are numerical, and in fact on a ratio scale (as they are counts), but because they are <em>discrete</em>, I want columns with gaps, not columns that touch, which seems to be the only option for histogram(). </p>
  
  <p>I currently have the following, but bar- and boxplot do not align quite perfectly: </p>
  
  <pre><code>set.seed(476372)
  counts1 &lt;- rpois(10000,3)
  nf &lt;- layout(mat = matrix(c(1,2),2,1, byrow=TRUE),  height = c(3,1))
  par(mar=c(3.1, 3.1, 1.1, 2.1))
  barplot(prop.table(table(counts1)))
  boxplot(counts1, horizontal=TRUE,  outline=TRUE,ylim=c(0,12), frame=F, width = 10)
  </code></pre>
  
  <p>Here my question: How can I make them align?</p>