I'm trying to plot some poll results but always have to add the legend manually after creating the plot. Here's my data (poll.csv):
Date,AKP,MHP,CHP,IYI,HDP,DEVA,GP,SP
01-05-2021,34.8,9,27.2,13.1,8.9,3.1,1.8,1.6
01-06-2021,36.2,9.1,20.3,16.7,10.5,3.6,1.3,0.6
01-14-2021,35,9.5,25,13,10.7,2.5,2.6,0.8
01-27-2021,35.6,8.5,24.9,13.6,8.9,2.3,2.5,1.6
01-30-2021,35.6,8.1,25.3,13.4,10.5,2.9,3,0.9
02-06-2021,35.8,7.8,24.2,12.7,11.4,4.6,1.3,0.8
02-08-2021,39.3,10.5,22.6,13.1,10.2,,,1.2
02-13-2021,35.2,9.6,21.1,15.6,10.6,3.8,1.7,1
02-13-2021,34.1,7.5,27.3,14,10.1,2.4,2.7,1.4
02-15-2021,35.2,9,26.5,12.9,9.9,2.5,1,1.5
02-23-2021,36.8,11.6,22.3,10.8,8.2,2.1,2.6,1.3
02-23-2021,41.7,11.6,21.8,10.3,9.3,1.8,0.4,0.8
02-26-2021,36.1,10,24.1,14,10.1,1.6,1.4,1.3
03-03-2021,34.8,7,26.2,13.1,9.1,2.5,2.7,0.7
03-06-2021,36.5,8.1,24,13.1,11,4,,
03-08-2021,36,9.9,26.3,13.5,8.7,2.1,1.9,1.1
03-10-2021,36,,29,,10.4,,,
03-11-2021,35.4,8.3,22,16.5,11.3,2.9,1.2,1.2
03-14-2021,34.4,7.2,26.2,13.9,9.6,2.7,2.8,0.8
and here's my code:
library(ggplot2)
library(anytime)
poll = read.csv("poll.csv")
poll$Date = as.Date(anydate(poll$Date))
ggplot(poll) +
geom_point(aes(x = Date, y = AKP), color = '#ff8700') +
geom_smooth(aes(x = Date, y = AKP), color = '#ff8700') +
geom_point(aes(x = Date, y = CHP), color = '#ff0000') +
geom_smooth(aes(x = Date, y = CHP), color = '#ff0000') +
geom_point(aes(x = Date, y = MHP), color = '#ff0019') +
geom_smooth(aes(x = Date, y = MHP), color = '#ff0019', se = FALSE) +
geom_point(aes(x = Date, y = HDP), color = '#8000ff') +
geom_smooth(aes(x = Date, y = HDP), color = '#8000ff', se = FALSE) +
geom_point(aes(x = Date, y = IYI), color = '#3db5e6') +
geom_smooth(aes(x = Date, y = IYI), color = '#3db5e6', se = FALSE) +
geom_point(aes(x = Date, y = SP), color = '#f50002') +
geom_smooth(aes(x = Date, y = SP), color = '#f50002', se = FALSE) +
geom_point(aes(x = Date, y = DEVA), color = '#0061a1') +
geom_smooth(aes(x = Date, y = DEVA), color = '#0061a1', se = FALSE) +
geom_point(aes(x = Date, y = GP), color = '#00564a') +
geom_smooth(aes(x = Date, y = GP), color = '#00564a', se = FALSE) +
scale_x_date(date_breaks = "3 months", date_labels = "%m/%y") +
labs(x = "", y = "") +
theme(axis.text.x = element_text(size = 20),
axis.text.y = element_text(size = 20))
I searched for answers but couldn't make any one of them work. How can I add a legend to the plot?