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 https://www.nature.com/articles/s41467-017-02546-5/figures/4). My data has been normalised to be around 0 so they are all on the same scale.
df2 sample:
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 I plot the expression levels with ggplot2:
plotC <- ggplot(df2, aes(x=variable, y=value, group=factor(gene), colour=gene)) + geom_line(size=0.5, aes(color=gene), alpha=0.4) But adding the mean line in red to this plot is proving difficult. I calculated the means and put them in another dataframe:
means value variable gene 1 -1.5037354 5 50 2 -0.8783492 6 50 3 -0.7769085 7 50 Then tried adding them as another layer:
plotC + geom_line(data=means, aes(x=variable, y=value, color="red", group=factor(gene)), size=0.75) But I get an error Error: Discrete value supplied to continuous scale
Do you have any suggestions as to how I can plot this mean on the same graph in another color?
Thank you, Anna
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... enter image description here
color = "red"outside of theaescall.