1

I have a dataframe named data with index, mean and median as variables. I have created the graph with this code.

ggplot(data, aes(x = index)) + 
  geom_line(aes(y = median), size = 1, colour="firebrick") + 
  geom_line(aes(y = mean), size = 1, colour = "dodgerblue4") + geom_point(size = 2, aes(y = median), colour = 'firebrick' ) +  
  geom_point(size = 2, aes(y = mean), colour = 'dodgerblue4' )

I want to add legend to this graph for median and mean. I am able to find legends only for factor of single variable. But not able to do it for two variables.

I am trying this,

scale_colour_manual("", breaks = c("Median", "Mean"),values = c("firebrick", "dodgerblue4"))

But no effect in the graph. Can anybody help me in doing this?

Thanks

Observer
  • 641
  • 2
  • 14
  • 31
  • @aosmith I saw the melt option already. But it was too complicated for my kind of requirement. So is there a better way to do this? – Observer Mar 31 '16 at 16:33
  • 2
    Then isn't the accepted answer exactly what you want? Did you see that `colour` was inside `aes`? [Here](http://stackoverflow.com/a/10355844/2461552) is another duplicate. – aosmith Mar 31 '16 at 16:47

0 Answers0