Hello I am trying to add a legend to my graph:
Having looked at a few previous answers they all seem to rely on aes() or having the lines be related to a factor in some way. I didn't understand this answer Add legend to geom_line() graph in r. In my case I simply want a legend that states "RED = No Cross Validation" and "BLUE = Cross Validation"
R Code
ggplot(data=graphDF,aes(x=rev(kAxis)))+
geom_line(y=rev(noCVErr),color="red")+
geom_point(y=rev(noCVErr),color="red")+
geom_line(y=rev(CVErr),color="blue")+
geom_point(y=rev(CVErr),color="blue")+
ylim(minErr,maxErr)+
ggtitle("The KNN Error Rate for Cross Validated and Non-Cross Validated Models")+
labs(y="Error Rate", x = "1/K")
Dataset
ks kAxis noCVAcc noCVErr CVAcc CVErr
1 1 1.00000000 1.0000000 0.00000000 0.8279075 0.1720925
2 3 0.33333333 0.9345238 0.06547619 0.8336898 0.1663102
3 5 0.20000000 0.8809524 0.11904762 0.8158645 0.1841355
4 7 0.14285714 0.8690476 0.13095238 0.8272727 0.1727273
5 9 0.11111111 0.8809524 0.11904762 0.7857398 0.2142602
6 11 0.09090909 0.8809524 0.11904762 0.7500891 0.2499109
7 13 0.07692308 0.8511905 0.14880952 0.7622103 0.2377897
8 15 0.06666667 0.7976190 0.20238095 0.7320856 0.2679144
9 17 0.05882353 0.7916667 0.20833333 0.7320856 0.2679144
10 19 0.05263158 0.7559524 0.24404762 0.7201426 0.2798574
11 21 0.04761905 0.7678571 0.23214286 0.7023173 0.2976827
12 23 0.04347826 0.7440476 0.25595238 0.6903743 0.3096257
13 25 0.04000000 0.7559524 0.24404762 0.6786096 0.3213904