I am trying to generate a legend for a line graph I have created using ggplot. From what I have been reading, the legend should be made automatically given I have changed the aesthetics of the graph and included the linetype within the aes function but it is not visible. I have been scouring through answers to this exact question online and have tried many approaches but nothing seems to be working. I think I am missing something quite minor. I tried using scale_linetype_manual but this did not produce a legend. Any help would be appreciated.
jpeg(filename = "careercurve.jpeg", width = 12, height = 10, units = "cm", res = 1200)
ggplot() +
scale_y_continuous(limits = c(0.5,0.8))+
geom_line(aes(x = Age, y = fwd.preds), data = fwd.predictions, linetype = 1) +
geom_line(aes(x = Age, y = def.preds), data = def.predictions, linetype = 2) +
geom_line(aes(x = Age, y = mid.preds), data = mid.predictions, linetype = 3) +
geom_line(aes(x = Age, y = ruck.preds), data = ruck.predictions, linetype = 4) +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black", size = 8), axis.title = element_text(size = 8), legend.position = "bottom")+
labs(x = "Age (years)", y = "AFL Player Rank/min (au)") +
geom_text(aes(x = 35.4, y = 0.535, label = "Fwd"), size = 3) +
geom_text(aes(x = 35.4, y = 0.50, label = "Def"), size = 3) +
geom_text(aes(x = 35.4, y = 0.575, label = "Mid"), size = 3) +
geom_text(aes(x = 35.4, y = 0.67, label = "Ruck"), size = 3)
dev.off()