I am using the following code to add vertical lines to the plot. How can I add legend for the vertical lines?
library(ggplot2)
x <- c(1:10)
y <-sin(x)
df <-data.frame(xvals=x, yvals=y)
p1 <- ggplot(df,aes(x,y)) +
geom_line() +
scale_x_continuous(limits = c(0, 10), breaks = seq(0, 10, 1), minor_breaks = seq(0, 10, 0.2)) +
scale_y_continuous(limits = c(-1, 1), breaks = seq(-1, 1, 0.5), minor_breaks = seq(-1, 1, 0.1)) +
geom_vline(aes(xintercept=3), color="red", linetype="dashed", size=1) +
geom_vline(aes(xintercept=5), color="blue", linetype="dashed", size=1)