Apologies, this was posted earlier but deleted as its is a duplicate question. The duplicate talks about using scale_colour_manual to add a legend to the plot however I could not get this to work, i have added my code below including this suggestion. Appreciate its probably frowned upon re-posting so feel free to delete once resolved.
I have the following plot and I wish to add a legend to the plot but cannot seem to be able too. I have included my code and plot below if anyone knows how to do this. I'm looking for red to be 'east, blue to be 'west and black to be 'overall. Also included a small bit of data to be replicated. I've had a look at other posts on here suggesting things like scale_colour_manual but unable to get it to work.
code used;
ggplot(climate_df_year, aes(y = overall_sst, x = year)) +
geom_line() +
geom_line(aes(y = eastern_sst, x = year), col = 'red', linetype = 2, size = 0.6) +
geom_line(aes(y = western_sst, x = year), col = 'blue', linetype = 2, size = 0.6) +
scale_colour_manual("",
breaks = c("Eastern", "Overall", "Western"),
values = c("red", "black", "blue")) +
ylab("SST (°C)") +
xlab("Year") +
theme(plot.title = element_text(hjust = 0.5, size = 12, face = 'bold'))
data
year overall_sst eastern_sst western_sst
1998 20.3 21.3 19.0
1999 20.6 21.6 19.2
2000 20.4 21.3 19.1
plot