title: How to fill in the variables into the stat_funciton() programmatically?
body: <p>I saw the answer to the question to &quot;filling in the variables into ggplot&quot;: <a href="https://stackoverflow.com/questions/49473915/r-how-do-i-use-selectinput-in-shiny-to-change-the-x-and-fill-variables-in-a-gg">R - How do I use selectInput in shiny to change the x and fill variables in a ggplot renderPlot?</a></p>
  <p>How can I do similar things to stat_function?</p>
  <p>Here's my code in side the renderPlot:</p>
  <pre><code>ggplot(data = removedNA,mapping = aes_string(x = input$x)) +  
    geom_histogram(aes(y = ..density..)) +    
    stat_function(fun = dnorm, n = 40000, args = list(mean = mean(input$x, na.rm = TRUE), sd = sqrt(var(input$x,na.rm = TRUE)))) +
    labs(title = input$x) 
  </code></pre>
  <p>I got the histogram and a Warning:
  <code>Warning in mean.default(input$x, na.rm = TRUE) :   argument is not numeric or logical: returning NA</code></p>