title: Unable to Pass Arguments in User Define Function to ggplot
body: <p>I want to create a user define function that wraps around some popular ggplot code I found. I am getting the following error: </p>
  
  <pre><code>"Error in `[.data.frame`(DS, , xvar) : object 'xcol' not found" 
  </code></pre>
  
  <p>The following is a small pseudo dataset to illustrate the issue.</p>
  
  <pre><code>n=25
  dataTest &lt;- data.frame(xcol=sample(1:3, n, replace=TRUE), ycol = rnorm(n, 5, 2), Cat=letters[1:5])
  </code></pre>
  
  <p>The user defined code is as here:</p>
  
  <pre><code>  TRIPLOT &lt;- function (DS,xvar,yvar,zvar) {
   #localenv&lt;-environment()
    gg &lt;- data.frame(x=DS[,xvar],y=DS[,yvar],fill=DS[,zvar])
    empty&lt;-ggplot()+geom_point(aes(1,1),colour="white") + theme( 
      plot.background = element_blank(),
      panel.background = element_blank(),
      panel.grid.minor = element_blank(),
      panel.border = element_blank(),
      panel.background = element_blank(),
      axis.title.x = element_blank(),
      axis.title.y = element_blank(),
      axis.text.x = element_blank(),
      axis.text.y = element_blank(),
      axis.ticks = element_blank())
    scatter &lt;-ggplot(gg, aes_string(x=xvar,y=yvar), environment=environment())+
      geom_point(aes_string(color=zvar))+
      scale_color_manual(values=c("orange","purple"))+
      theme(legend.position=c(1,1), legend.justification=c(1,1))
    plot_top &lt;- ggplot(gg,aes_string(x=xvar, fill=zvar), environment=environment())+geom_density(alpha=.5)+scale_fill_manual(values=c("orange","purple"))+theme(legend.position="none")
    plot_right &lt;- ggplot(gg, aes_string(yvar, fill=zvar),environment=environment())+geom_density(alpha=.5)+coord_flip()+ scale_fill_manual(values=c("orange","purple"))+
      theme(legend.position="none", axis.title.x=element_blank())
    PLT &lt;- grid.arrange(plot_top,empty,scatter,plot_right, ncol=2,nrow=2,widths=c(4,1), heights=c(1,4))
    print(PLT)
  }
  </code></pre>
  
  <p>The function I am trying to run is the following:</p>
  
  <pre><code>TRIPLOT(dataTest,"xcol","ycol","Cat")
  </code></pre>
  
  <p>I added environment argument and the data.frame() argument as recommend by the post. I have also passed the arguments to the function in quotes.
  Thank you for any help.</p>