title: ggplot2 variables within function
body: <p>Feel I am making a very dumb mistake here.. as I've done this before on another project (maybe luck?)</p>
  
  <p>Goal is to construct several graphs in ggplot via use of a function. I eventually want all the graphs displayed on a single page, etc...</p>
  
  <p>Here is an example of a single ggplot that works:</p>
  
  <pre><code>if (require("ggplot2") == FALSE) install.packages("ggplot2")
  
  data_df = data.frame(matrix(rnorm(200), nrow=20))
  time=1:nrow(data_df)
  
  ggplot(data=data_df, aes(x=time, y=data_df[,1])) + 
          geom_point(alpha=1/4) + 
          ggtitle(deparse(substitute(data_df[1])))
  </code></pre>
  
  <p>Note there are other functions that will be called within this that will change based on the dataframe column called.
  I followed another working example I had made, but this just gives me an error. I feel like I'm making an elementary mistake but can't put my finger on it!</p>
  
  <pre><code>if (require("ggplot2") == FALSE) install.packages("ggplot2")
  
  data_df = data.frame(matrix(rnorm(200), nrow=20))
  time=1:nrow(data_df)
  
  graphit &lt;- function(sample_num){
          ggplot(data=data_df, aes(x=time, y=data_df[,sample_num])) + 
                  geom_point(alpha=1/4) + 
                  ggtitle(deparse(substitute(data_df[sample_num])))
  }
  
  graphit(1)
  
  #Error in `[.data.frame`(data_df, , sample_num) : 
  #  object 'sample_num' not found
  </code></pre>
  
  <p>Thanks for any help.            </p>