0

I have the following dataframe:

enter image description here

and I am trying to add geom_point for columns: radiopred, tvpred, newspaperpred and allpred. But I need to add a legend to distinguish between points from the 4 columns.

  ggplot() +
    geom_point(mapping=aes(x=Sales,y=allpred), colour='blue') +
    geom_point(mapping=aes(x=Sales,y=radiopred), colour='red') +
    geom_point(mapping=aes(x=Sales,y=tvpred), colour='green') +
    geom_point(mapping=aes(x=Sales,y=newspaperpred), colour='purple')

enter image description here

Just missing the legend.

Chipmunkafy
  • 566
  • 2
  • 5
  • 17
  • 1
    Probable [duplicate](https://stackoverflow.com/q/10349206/324364). – joran Mar 14 '19 at 21:18
  • 3
    This comes up fairly often (looks like someone already found a dupe) so I wrote a little [post](https://aosmith.rbind.io/2018/07/19/legends-constants-for-aesthetics-in-ggplot2/) about this last summer. – aosmith Mar 14 '19 at 21:19

0 Answers0