title: Combining a box plot with a dot plot using different Y scales
body: <p>I am trying to generate a figure that consists of a box plot with a set of points overlaid on the boxplot. The key issue is that the y scale of the box plot is different from that of the points. (Yes, this is very poor visualization - but I'm not the lead author of the paper). I have been able to generate a plot with different y scales, but am facing an issue with the x axis. </p>
  
  <p>Using the following code</p>
  
  <pre><code>boxdata &lt;- data.frame(fc=runif(100, min=-4, max=4),
                        sym=sample(c('A', 'B', 'C', 'D', 'E'), 100, replace=TRUE))
  par(mar=c(5, 4, 1, 6) + 0.1)
  junk &lt;- boxplot(fc ~ sym, boxdata, las=2, pch=19, ylim=c(-5,5),
                  varwidth=FALSE, xaxt='n')
  mtext("Y-axis",side=2,line=2.5)
  axis(1, at=1:5, labels=sort(unique(boxdata$sym)), las=2)
  
  par(new=TRUE)
  x &lt;- 1:5
  y &lt;- runif(5, min=-1, max=1)
  plot(x,y, col='red', type='p', pch=15, axes=FALSE, ylim=c(-1,1), cex=1.5)
  axis(4, ylim=c(-1,1), las=1)
  </code></pre>
  
  <p>I get the following figure. As you can see the points in red do not align with the X-axis labels (or box centers). The box centers are located at 1:5, so I thought that the plot() call with x = 1:5 should line up.</p>
  
  <p>Could anybody point me to a way to line up the second set of points with the box centers?</p>
  
  <p><img src="https://i.stack.imgur.com/MkWrg.png" alt=""></p>
  
  <p>EDIT: This problem doesn't occur if I plot two sets of points on different y scales</p>
  
  <pre><code>plot(1:10, runif(10) , col='red', pch=19)
  par(new=TRUE)
  plot(1:10, runif(10, min=5, max=20), col='blue', pch=19, axes=FALSE)
  axis(4, las=2)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/6Jk05.png" alt=""></p>