I am trying to add labels in line graph but am unable to do so. I want to add lable such that blue line mentiones 'model_1'; red line mentioned 'model_2' and darkgreen line mentioned 'model_3'
Attaching the code below
p1 <- ggplot(data = Auto, aes(x = horsepower, y = mpg)) +
  geom_point() +
  geom_line(aes(y = fitted(lm_mpg_1)), color = "blue", size = 1) +
  geom_line(aes(y = fitted(lm_mpg_2)), color = "red", size = 1) +
  geom_line(aes(y = fitted(lm_mpg_3)), color = "darkgreen", size = 1)
I have tried to use geom_text, geom_label and annotate function however they give me error.
The code I tried was:
p1 + geom_text(label = c('model_1','model_2','model_3'))
 
     
    