title: Local Variables Within aes
body: <p>I'm trying to use a local variable in <code>aes</code> when I plot with ggplot. This is my problem boiled down to the essence:</p>
  
  <pre><code>xy &lt;- data.frame(x=1:10,y=1:10)
  
  plotfunc &lt;- function(Data,YMul=2){
      ggplot(Data,aes(x=x,y=y*YMul))+geom_line()
  }
  
  plotfunc(xy)
  </code></pre>
  
  <p>This results in the following error:</p>
  
  <pre><code>Error in eval(expr, envir, enclos) : object 'YMul' not found
  </code></pre>
  
  <p>It seems as if I cannot use local variables (or function arguments) in <code>aes</code>. Could it be that it occurrs due to the content of <code>aes</code> being executed later when the local variable is out of scope? How can I avoid this problem (other than not using the local variable within <code>aes</code>)?</p>