how to add legend in goem_hline() in R

Hi,

I can't reproduce your code, but you can use geom_hline(aes(.., linetype =... ) ) with scale_linetype_manual() . Try to add

geom_hline(aes(yintercept = 18, linetype = "historical average"), colour = "blue") +
scale_linetype_manual(name ="", values = c('dotted')) #for e. g. dotted hline

to your code and see if it gives you what you're looking for.

JW

1 Like