I've been searching the answer for two days and still can't find how to do this. The closest cases I found
CodePudding user response:
If you want to get a legend you have to map on an aesthetic, e.g. you could map on the shape
aes to get a legend for your points too:
library("ggplot2")
ggplot(MyDF, aes(x = Year, y = TheData))
geom_point(aes(y = TheData, shape = "TheData"), size = 2.5)
geom_line(aes(x = Year, y = Model, color = "Model"))
geom_ribbon(aes(ymin = Lower, ymax = Upper, x = Year,
fill = "Confidence Interval"), alpha = 0.15)
scale_colour_manual(
name = "", values = c("Confidence Interval" = "transparent",
"Model" = "black"))
scale_fill_manual(
name = "", values = c("Confidence Interval" = "grey12",
"Model" = "transparent"))
theme(legend.position = "bottom")
labs(shape = "")