title: How to use a variable to specify column name in ggplot
body: <p>I have a ggplot command</p>
  
  <pre><code>ggplot( rates.by.groups, aes(x=name, y=rate, colour=majr, group=majr) )
  </code></pre>
  
  <p>inside a function. But I would like to be able to use a parameter of the function to pick out the column to use as colour and group. I.e. I would like something like this</p>
  
  <pre><code>f &lt;- function( column ) {
      ...
      ggplot( rates.by.groups, aes(x=name, y=rate, colour= ??? , group=??? ) )
  }
  </code></pre>
  
  <p>So that the column used in the ggplot is determined by the parameter. E.g. for f("majr") we get the effect of</p>
  
  <pre><code>ggplot( rates.by.groups, aes(x=name, y=rate, colour=majr, group=majr) )
  </code></pre>
  
  <p>but for f("gender") we get the effect of</p>
  
  <pre><code>  ggplot( rates.by.groups, aes(x=name, y=rate, colour=gender, group=gender) )
  </code></pre>
  
  <p>Some things I tried:</p>
  
  <pre><code>ggplot( rates.by.groups, aes(x=name, y=rate, colour= columnName , group=columnName ) )
  </code></pre>
  
  <p>did not work. Nor did </p>
  
  <pre><code>e &lt;- environment() 
  ggplot( rates.by.groups, aes(x=name, y=rate, colour= columnName , group=columnName ), environment=e )
  </code></pre>