title: ggplot scale transformation inaccurate for stat_function
body: <p>I have some right-skewed data, and I'd like to visually compare distribution fits to the data on the regular scale and the log-scale using ggplot.  However, when I use the scale_x_continuous() or scale_x_log10() to convert the distribution curves, the transformation does not translate correctly.</p>
  
  <pre><code>x &lt;- rlnorm(1000, meanlog = -4, sdlog = 1)
  ggplot(data.frame(x)) +
    geom_histogram(aes(x, y = ..density.. * 25)) +
    scale_x_log10() +
    stat_function(fun = "dlnorm",
                  args = list(meanlog = -4,
                              sdlog = 1))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Ksvzb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ksvzb.png" alt="histogram on log scale"></a></p>
  
  <p>Notice how the mean of the lognormal curve does not match the mean of the histogram.  Why not? Is there a way to get them to match?</p>
  
  <p>In a different but related post, a suggested answer was to include the argument <code>inherit.aes = FALSE</code>, but that does not help here.</p>
  
  <p>I am using R version 3.4.3 and ggplot2 version 2.2.1.</p>