I am trying to manually add legend to my ggplot, however, am getting nowhere. Did a few searches but couldn't find a relevant solution. Here is my code so far
library(tidyverse)
library(zoo)
FakeData = data.frame(A = runif(184, 50,100), B = A + 20, C = A + 40, D = A -20, E = A-10, F = A-15, G = seq(1:184))
lab=c("May", "Jun","July", "Aug","Sep","Oct", "Nov")
ggplot(FakeData, aes(G, ymin=A, ymax=B))+geom_ribbon(fill= "grey75")+geom_line(aes(G, C),linetype = "dashed", col = "red", size = 1.3)+
geom_line(aes(G, D),linetype = "dashed", colour = "black", size = 1.3)+
geom_line(aes(G, E), colour = "darkblue", size = 1.3)+ geom_point(aes(G, F), col = "blue", size = 1.3)+
scale_x_continuous(breaks = c(0,31,61,92,123,153,184), labels = lab)+ xlab("Month")+ ylab("Daily Cumulative Precipitation (mm)")+ theme_bw()
I would like to add below legends for the Figure
Leg = c("Upper and lower Quartile", "Maximum", "Minimum", "Median", "Precipitation")
Edits to ggplot
I modified the ggplot code based on suggestions, however, the data color does not correspond to its legend. For example, the Max data which is color coded as red should be at the top of all other data in the figure, however, it is not- Likewise for other legends.
ggplot(FakeData)+geom_ribbon(aes(G, ymin=A, ymax=B, col = "cyan"), alpha = 0.3)+geom_line(aes(G, C, col = "red"),linetype = "dashed", size = 1.3)+
geom_line(aes(G, D, col = "black"),linetype = "dashed", size = 1.3)+
geom_line(aes(G, E, col = "darkblue"), size = 1.3)+ geom_point(aes(G, F, col = "blue"), size = 1.3)+
scale_x_continuous(breaks = c(0,31,61,92,123,153,184), labels = lab)+ xlab("Month")+ ylab("Daily Cumulative Precipitation (mm)")+ theme_bw()+
scale_color_manual(labels = c("Upper and lower Quartile", "Maximum", "Minimum", "Median", "Precipitation"), values = c("cyan", "red","black", "darkblue","blue") )
Here is the plot for the updated code where the legends are not directing to the right data plot.
The final product should be a figure somewhat like this (the legend is displayed on the left top cornor.