title: R - ggplot passing color by variable
body: <p><strong>file.csv</strong></p>
  
  <pre><code>group   metric
  "1"       1.1
  "0"       2.2
  "0"       3.3
  "1"       4.4
  </code></pre>
  
  <p>I'm reading the above <code>file.csv</code> as below in to a data frame</p>
  
  <pre><code>df &lt;- read.csv("file.csv", header=T)
  # store col names for using later
  group_name &lt;- colnames(df)[1]
  metric_name &lt;- colnames(df)[2]
  </code></pre>
  
  <p>While creating a box plot, I need to pass the color through variable <code>group_name</code></p>
  
  <pre><code>p &lt;- ggplot(data=df, aes(x=df[,group_name], y=df[,metric_name], color=group_name ) ) +
    geom_boxplot(outlier.colour="darkred", outlier.shape = NA, fill = fill, color=line, alpha = 0.5) +
    theme(legend.position = c(1, 1), legend.justification = c(1, 1))
  p
  </code></pre>
  
  <p>The issue is that the legend in the plot shows as <code>group_name</code> instead of the value of the variable <code>group_name</code> - what is needed to done so that color takes the value of the variable <code>group_name</code> ?</p>
  
  <p>The reason for using <code>x=df[,group_name]</code> in <code>aes</code> is so as to make it generally applicable for any csv files whole column name may not be known.</p>