I know an identical question has been asked earlier. ggplot legend - scale_colour_manual not working
But the question involves a somewhat complicated dataset than wh
You have to use show_guide=TRUE
in geom_vline
(defaults to FALSE
):
p <- data.frame(a = runif(10, 1, 2))
ggplot(data=p, aes(x=a)) +
geom_histogram() +
geom_vline(aes(xintercept=mean(a), colour="mea"), show_guide=TRUE) +
geom_vline(aes(xintercept=median(a), colour="med"), show_guide=TRUE) +
scale_colour_manual(name="Statistic",
values=c("med"= "red", "mea"="green"))