title: ggplot2: adding lines in a loop and retaining colour mappings
body: <p>When running the following two pieces of code, I unexpectedly get different results. I need to add lines in a loop as in EX2, but all lines end up having the same colour. Why is this?</p>
  <h1>EX1</h1>
  <pre><code>economics2 &lt;- economics
  economics2$unemploy &lt;- economics$unemploy + 1000
  economics3 &lt;- economics
  economics3$unemploy &lt;- economics$unemploy + 2000
  economics4 &lt;- economics
  economics4$unemploy &lt;- economics$unemploy + 3000
  b &lt;- ggplot() +
   geom_line(aes(x = date, y = unemploy, colour = as.character(1)), data=economics2) +
   geom_line(aes(x = date, y = unemploy, colour = as.character(2)), data=economics3) +
   geom_line(aes(x = date, y = unemploy, colour = as.character(3)), data=economics4)
  print(b)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DhkxV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DhkxV.png" alt="EX1" /></a></p>
  <h1>EX2</h1>
  <pre><code>#economics2, economics3, economics4 are reused from EX1.
  b &lt;- ggplot()
  econ &lt;- list(economics2, economics3, economics4)
  for(i in 1:3){
    b &lt;- b + geom_line(aes(x = date, y = unemploy, colour = as.character(i)), data=econ[[i]])
  }
  print(b)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Y7XS5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y7XS5.png" alt="EX2" /></a></p>