I have a plot in ggplot with 4 separate lines that I have added with a separate geom_line() argument. I would like to add legend but scale_colour_manual doesn't work in this case. What is the proper way to add legends when I added the variables separately?
Here's my code:
ggplot(proba[108:140,], aes(c,four)) +
geom_line(linetype=1, size=0.3) +
scale_x_continuous(breaks=seq(110,140,5)) +
theme_bw() +
theme(axis.line = element_line(colour = "black", size=0.25),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank()) +
theme(axis.text.x = element_text(angle = 0, hjust = +0.5, size=6,color="black")) +
theme(axis.text.y = element_text(angle = 0, hjust = -100, size=6, color="black")) +
theme(axis.ticks=element_line(colour="black",size=0.25)) +
xlab("\nTime-steps") +
ylab("Proportion correct\n") +
theme(axis.text=element_text(size=8),axis.title=element_text(size=8)) +
geom_line(aes(c,three), size=0.2, linetype=2) +
geom_line(aes(c,one),linetype=3, size=0.8, colour="darkgrey") +
geom_line(aes(c,two), linetype=1, size=0.8, colour="darkgrey")
color="Line Name"
in the call toaes
should work. – Peytoncolor
argument insideaes
, and rather than setting it to the color name, set it to the name you want to appear in the legend. Then usescale_color_manual
to map that name to the desired color. – Peyton