I have the below code and the legend is all wrong. The black line shows up purple and in the legend the color labels are wrong. for red it says black, etc.
ggplot(newdata,aes(x=immigrants.per.day,y=cc.percent),show.legend = TRUE) +
+ stat_summary(aes(y = cc.percent, color = "red"),fun = mean, geom = "line", label = c('CC'), show.legend = TRUE) +
+ stat_summary(aes(y = cd.percent, color = "blue"),fun = mean, geom = "line", show.legend = TRUE) +
+ stat_summary(aes(y = dc.percent, color = "green"),fun = mean, geom = "line", show.legend = TRUE) +
+ stat_summary(aes(y = dd.percent, color = "black"),fun = mean, geom = "line", show.legend = TRUE)
i did follow links below but not able to solve my problem.
How can I add the legend for a line made with stat_summary in ggplot2?