title: ggplot multiple lines in same graph
body: <p>I am trying to plot multiple gene expressions over time in the same graph to demonstrate a similar profile and then add a line to illustrate the mean of total for each timepoint (like the figure 4b in recent Nature comm article <a href="https://www.nature.com/articles/s41467-017-02546-5/figures/4" rel="nofollow noreferrer">https://www.nature.com/articles/s41467-017-02546-5/figures/4</a>). My data has been normalised to be around 0 so they are all on the same scale. </p>
  
  <p>df2 sample:</p>
  
  <pre><code>variable    value   gene
  1   5   -0.610384193    1
  2   5   -6.25967087 2
  3   5   -3.773389731    3
  50  6   -0.358879035    1
  51  6   -6.066341017    2
  52  6   -4.202998579    3
  99  7   -0.103885903    1
  100 7   -6.648844687    2
  101 7   -5.041554127    3
  </code></pre>
  
  <p>I plot the expression levels with ggplot2:</p>
  
  <pre><code>plotC &lt;- ggplot(df2, aes(x=variable, y=value, group=factor(gene), colour=gene)) + geom_line(size=0.5, aes(color=gene), alpha=0.4)
  </code></pre>
  
  <p>But adding the mean line in red to this plot is proving difficult. I calculated the means and put them in another dataframe:</p>
  
  <pre><code>means
         value variable gene
  1 -1.5037354        5   50
  2 -0.8783492        6   50
  3 -0.7769085        7   50
  </code></pre>
  
  <p>Then tried adding them as another layer:</p>
  
  <pre><code>plotC + geom_line(data=means, aes(x=variable, y=value, color="red", group=factor(gene)), size=0.75)
  </code></pre>
  
  <p>But I get an error <code>Error: Discrete value supplied to continuous scale</code></p>
  
  <p>Do you have any suggestions as to how I can plot this mean on the same graph in another color?</p>
  
  <p>Thank you,
  Anna</p>
  
  <p>edit: the answer by RG20 is helpful, thanks for pointing out I had the color in the wrong place. However it plots the line outside the rest of the graph... I really don't understand what's wrong with my graph...
  <a href="https://i.stack.imgur.com/YWIVw.png" rel="nofollow noreferrer">enter image description here</a></p>