title: add a secondary y axis to ggplot2 plots - make it perfect
body: <p>Adding a secondary y axis, scaled one of the original y axis. This topic is not new. It has been touched times, for example <a href="http://groups.google.com/group/ggplot2/browse_thread/thread/b48984c4f660eb5a?pli=1" rel="nofollow noreferrer">on this ggplot2 google groups thread</a>. Following Hadley's advice, I tried to add the secondary y axis by <code>geom_vline</code>, <code>geom_segment</code>, and <code>geom_text</code>. But, it is still ugly. </p>
  
  <p>So I would ask for your help on making it perfect. I think many ggplot2 users would be interested in this topic and prefer any your expertise or contributions. Thanks in advance.</p>
  
  <pre><code>#########################################
  # what I have gotten.
  library(ggplot2)
  
  # build up a box plot
  p &lt;- ggplot(mtcars, aes(factor(cyl), mpg)) 
  
  # add the secondary y axis on right side of the plot
  p + geom_boxplot() + geom_vline(xintercept = 3.5) + 
   geom_segment(aes(x=3.49, y=c(7,14,21,28), xend = 3.52, yend = c(7,14,21,28))) +
   geom_text(aes(x=3.55, y=c(7,14,21,28), label=c(7,14,21,28)))
  </code></pre>