How to create a legend for this plot ?

db<-read.csv(file = "alldata1.csv", sep = ",")
HwE1<-db$HE1-404.1822
# The above number is the Bed Altitude at station E1, w=41 m
QE1<-db$QE1
A1E1<-(2*41-HwE1)*(HwE1/2) # Trapezoid cross-section
U1E1<-QE1/(A1E1)
A2E1<-(0.5*41*HwE1) # Triangular
U2E1<-QE1/(A2E1)
A3E1<-((2/3)*41*HwE1) # Parabola
U3E1<-QE1/(A3E1)

idE1<- 1:length(HwE1)
FxE1 <- idE1/(1+length(idE1))
# D =Pier Diameter (D), d50 = Sediment size. D/d50 =750, D= 1.5m
#Wu`s model OC`
ds1OCWE1 =2.9*(((U1E1^2)/(9.81*1.5))^0.05)*((HwE1/1.5)^0.17)*((750)^-0.18)
ds2OCWE1 =2.9*(((U2E1^2)/(9.81*1.5))^0.05)*((HwE1/1.5)^0.17)*((750)^-0.18)
ds3OCWE1 =2.9*(((U3E1^2)/(9.81*1.5))^0.05)*((HwE1/1.5)^0.17)*((750)^-0.18)


#HEC-18-loc OC .. local scour for open channel
ds1HEClocE1=2*1*1.1*1*((HwE1/1.5)^0.35)*(U1E1/sqrt(9.81*HwE1))^0.43
ds2HEClocE1=2*1*1.1*1*((HwE1/1.5)^0.35)*(U2E1/sqrt(9.81*HwE1))^0.43
ds3HEClocE1=2*1*1.1*1*((HwE1/1.5)^0.35)*(U3E1/sqrt(9.81*HwE1))^0.43

#HEC-18 sediment transport concepts and theory (Richardson et al. 2001)#contraction scour
dsHECE1=((((0.025*(db$QE1^2))/(0.01842*(41*0.9)^2))^(3/7))-HwE1)/1.5 #D=1.5m


#Wu`s model Ice coverage`

ds1ICE1 =3.7*(((U1E1^2)/(9.81*1.5))^0.05)*((HwE1/1.5)^0.11)*((750)^-0.18)
ds2ICE1 =3.7*(((U2E1^2)/(9.81*1.5))^0.05)*((HwE1/1.5)^0.11)*((750)^-0.18)
ds3ICE1 =3.7*(((U3E1^2)/(9.81*1.5))^0.05)*((HwE1/1.5)^0.11)*((750)^-0.18)



library(ggplot2)
dfds1E1<-data.frame(FxE1,ds1HEClocE1,ds1OCWE1,ds1ICE1)
y2=sort(ds1OCWE1, decreasing = F)
y1=sort(ds1HEClocE1, decreasing = F)
y3=sort(ds1ICE1, decreasing = F)
ggplot(dfds1E1,aes(x=FxE1, y=y1))+geom_line(aes(x=FxE1, y=y1), color="red")+geom_line(aes(x=FxE1, y=y2), color="blue")+geom_line(aes(x=FxE1, y=y3), color="brown")+labs(title = "Station E1-Trapezoidal corss-section", x="CDF",y="Normalized scour depth")

dfds2E1<-data.frame(FxE1,ds2HEClocE1,ds2OCWE1,ds2ICE1)
t2=sort(ds2OCWE1, decreasing = F)
t1=sort(ds2HEClocE1, decreasing = F)
t3=sort(ds2ICE1, decreasing = F)
ggplot(dfds2E1,aes(x=FxE1, y=t1))+geom_line(aes(x=FxE1, y=t1), color="red")+geom_line(aes(x=FxE1, y=t2), color="blue")+geom_line(aes(x=FxE1, y=t3), color="brown")+labs(title = "Station E1-Triangular corss-section", x="CDF",y="Normalized scour depth")

dfds3E1<-data.frame(FxE1,ds3HEClocE1,ds3OCWE1,ds3ICE1)
p2=sort(ds3OCWE1, decreasing = F)
p1=sort(ds3HEClocE1, decreasing = F)
p3=sort(ds3ICE1, decreasing = F)
ggplot(dfds3E1,aes(x=FxE1, y=p1))+geom_line(aes(x=FxE1, y=p1), color="red")+geom_line(aes(x=FxE1, y=p2), color="blue")+geom_line(aes(x=FxE1, y=p3), color="brown")+labs(title = "Station E1-Parabolic corss-section", x="CDF",y="Normalized scour depth")

Without any data it is difficult to see what you are but it looks like you have a single line in each plot. If so, I believe the ggplot2 philosophy is that you do not need a legend as it is redundant ---and what Tufte would term "chart junk".

If you mean that you need separate titles for each plot have a look at theme Modify components of a theme — theme • ggplot2

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.