title: Create ggplot2 function and specify arguments as variables in data as per ggplot2 standard functionality
body: <p>I want to create a plotting function where I specify the data set, and specify the plotting arguments as function arguments in similar fashion as I can within <code>ggplot2</code>, i.e. where we specify the variable name without the dataset, e.g. <code>hp</code> instead of <code>mtcars$hp</code>.</p>
  
  <p>For example:</p>
  
  <pre><code>ggfun &lt;- function(dat, x.var, y.var){
  
    ggp &lt;- ggplot(data = dat,
                  aes(x = x.var,
                      y = y.var)) +
      geom_point()
  
    return(ggp)
  }
  
  
  ggfun(dat = mtcars, x.var = drat, y.var = hp)
  </code></pre>
  
  <p>Would return:
  <a href="https://i.stack.imgur.com/eqecj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eqecj.png" alt="wonderful plot"></a></p>
  
  <p>However it returns:</p>
  
  <pre><code>&gt; ggfun(dat = mtcars, x.var = drat, y.var = hp)
  Error in eval(expr, envir, enclos) : object 'drat' not found
  In addition: Warning message:
  In eval(expr, envir, enclos) : restarting interrupted promise evaluation
  </code></pre>
  
  <p>I know <a href="https://stackoverflow.com/a/49948143/2706826">using <code>aes_string</code> instead of <code>aes</code> works</a>, e.g.:</p>
  
  <pre><code>ggfun &lt;- function(dat, x.var, y.var){
  
    ggp &lt;- ggplot(data = dat,
                  aes_string(x = x.var,
                      y = y.var)) +
      geom_point()
  
    return(ggp)
  }
  
  ggfun(dat = mtcars, x.var = "drat", y.var = "hp")
  </code></pre>
  
  <p>But I'd prefer to avoid using string form.</p>
  
  <p>Other attempts include <code>ggfun(dat = mtcars, x.var = mtcars$drat, y.var = mtcars$hp)</code>, which returns the right graph but partially defeats the purpose of the exercise, and produces lables "x.var" and "y.var" instead of "drat" and "hp".</p>
  
  <p>Any known <em>and reasonably simple</em> way around this?</p>