title: R pass variable column indices to ggplot2
body: <p>I'm attempting to pass the column indices to ggplot as part of a function I'll be using repeatedly.
  like:</p>
  <pre><code>myplot &lt;- function(df){
      ggplot(df, aes(df[, 1], df[, 2])) + geom_point()
  }
  </code></pre>
  <p>I'll always be using the first column as my x variable and the second column as my y-variable, but the column names change between data sets.  I've searched all over.. Any ideas?</p>
  <h1>EDIT:</h1>
  <p><strong>This is the answer I used:</strong></p>
  <pre><code>require(ggplot2)
  
  myplot &lt;- function(df){
     ggplot(df, aes_string(colnames(df)[1], colnames(df)[2])) + geom_point()
  }
  </code></pre>