I am new R user. I tried to add legend of mean data of df_summary1 and df_summary2 with title "RCP4.5" and "RCP8.5" in my ggplot but fail. Can any one help me on this. Thanks in advance.
ggplot()+
geom_line(data=df_tidy1, aes(x=date, y=Ratio, group=Cell), color="grey") +
geom_line(data=df_tidy2, aes(x=date, y=Ratio, group=Cell), color="grey")+
geom_line(data = df_summary1, aes(x = date, y=mean), color = "red") +
geom_line(data = df_summary2, aes(x = date, y=mean), color = "blue")+
geom_ribbon(data =df_summary1, aes(x= date, ymin=CI_lower, ymax=CI_upper) ,fill="blue", alpha=0.2)+
geom_ribbon(data =df_summary2,aes(x= date, ymin=CI_lower, ymax=CI_upper) ,fill="grey", alpha=0.2)+
xlab("data") + ylab("Average temperature")
Here is the graph
the df_tidy1 look like:
data.frame(stringsAsFactors=FALSE,
date = c("1980-01-01", "1981-01-01", "1982-01-01", "1983-01-01",
"1984-01-01", "1985-01-01"),
Cell = c("Acsess.4.5", "Acsess.4.5", "Acsess.4.5", "Acsess.4.5",
"Acsess.4.5", "Acsess.4.5"),
Ratio = c(29.8715846994536, 29.5917808219178, 29.7479452054795,
30.2602739726027, 29.266393442623, 29.5342465753425)
)
the df_summary look like
data.frame(
date = c("1980-01-01", "1981-01-01", "1982-01-01", "1983-01-01",
"1984-01-01", "1985-01-01"),
n = c("5", "5", "5", "5", "5", "5"),
mean = c("29.8715846994536", "29.5917808219178", "29.7479452054795",
"30.2602739726027", "29.266393442623", "29.5342465753425"),
sd = c("0", "0", "0", "0", "0", "0"),
sem = c("0", "0", "0", "0", "0", "0"),
CI_lower = c("29.8715846994536", "29.5917808219178", "29.7479452054795",
"30.2602739726027", "29.266393442623", "29.5342465753425"),
CI_upper = c("29.8715846994536", "29.5917808219178", "29.7479452054795",
"30.2602739726027", "29.266393442623", "29.5342465753425")
)