Here is a simple example:
library(ggplot2)
library(data.table)
x<-data.table(y=rnorm(10),x=seq(1,10))
ggplot(x,aes(x=x,y=y))+geom_point()+geom_vline(aes(colour="a",xintercept=5))+
scale_color_manual(name="",labels=c("My Line"),
values=c("a"="black"))
I would like line in the legend to be horizontal rather than vertical but have not managed to achieve that, maybe somebody has a suggestion.
I have a little bit hacky solution:
ggplot(x,aes(x=x,y=y))+geom_point()+geom_vline(aes(xintercept=5))+
geom_hline(aes(colour="a",yintercept=Inf))+
scale_color_manual(name="",labels=c("Super"),
values=c("a"="black"))+
theme_bw()+
theme(legend.position = "top")
Maybe somebody can propose something better.