Using colors in aes() function in ggplot2
<p>I am new to <code>ggplot2</code>. I am trying to understand how to use <code>ggplot</code>. I am reading Wickham's book and still trying to wrap my head around how to use <code>aes()</code> function. In a related thread, we discussed that we should try to avoid using variables inside <code>aes()</code> i.e. "Don't put constants inside <code>aes()</code> - only put mappings to actual data columns."</p>

<p>My objective is to observe the behavior of ggplots when we have color inside <code>aes()</code> for labeling (as described in Wickham's book) and also override the color to print the color. </p>

<p>I started with this:</p>

<pre><code>library(ggplot2)
data(mpg)
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(aes(colour = "loess"), method = "loess", se = FALSE) +
  geom_smooth(aes(colour = "lm"), method = "lm", se = FALSE) +
  labs(colour = "Method")
</code></pre>

<p>This nicely plots graphs and labels them. However, I am unhappy with the colors used. So, I experimented with using overriding colors again:</p>

<pre><code>windows()
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(aes(colour = "loess"), method = "loess", se = FALSE, color = "magenta") +
  geom_smooth(aes(colour = "lm"), method = "lm", se = FALSE, color = "red") +  
  labs(colour ="Method")
</code></pre>

<p>I added color = "red" and we can see that <code>labs()</code> or <code>aes(color())</code> doesn't have any effect. Why does this happen? I'm curious. I'd appreciate thoughts.</p>