title: Conditionally set an aes mapping for ggplot2
body: <p>I am trying to conditionally set an aes mapping based on a boolean. Here is what I am trying to do:</p>
  
  <pre><code>mydata &lt;- data.frame(x=1:10, 
                       y=runif(10), 
                       categoryShort=LETTERS[1:2], 
                       categoryLong=LETTERS[1:5])
  mybool &lt;- TRUE
  myaes &lt;- aes(x=x, y=y, 
               colour=ifelse(mybool, factor(categoryShort), factor(categoryLong)))
  ggplot(mydata, myaes) + geom_point()
  </code></pre>
  
  <p>It ignores colour and screws up the whole legend.</p>
  
  <p>I tried using aes_string, but it had the same problem:</p>
  
  <pre><code>aes_string(x="x", y="y", 
             colour=factor(ifelse(mybool, "categoryShort", "categoryLong")))
  </code></pre>