I've produced a graph from my data in RStudio using ggplot2, and to show the comparison between my x/y variables, I've added the line y=x using geom_abline()
:
ggplot(data=my_df, aes(x=x, y=y)) +
geom_point() +
geom_abline(aes(slope=1, intercept=0, colour="x=y")) +
The code is generalised and omits lines for my axis labels etc. The code within geom_abline()
is my closest attempt at generating the legend. You can see that the legend title is "colour", but I want to change it to "legend" and haven't found a way to do so.
This is different from the stack exchange qu. "How to change legend title in ggplot" because I'm modifying the legend of a new line added, not my original plots, thus the answers in that question have had no effect. I don't understand what parameters like colour = "x=y"
are doing within abline
or how to change them.
Version of RStudio: 1.0.143
Version of ggplot2: 2.2.1