Add geom_hline to ggplot2 legend

Scott Prevost

2019/03/11

library(pander)
library(tidyverse)
library(lubridate)

a = data.frame(x_val = seq(from = ymd_hms("2050-01-01 00:00:00"),
                           to = ymd_hms("2050-12-31 23:59:59"),
                           by = "1 day"),
               y_val = 1:365)

plt = ggplot(data = a) +
  geom_line(aes(x = x_val,
                y = y_val,
                colour = "Variable"), # if there are multiple variables then change that to column heading
            size = 0.1) +
  geom_hline(aes(yintercept = 32,
                 linetype = "Legend")) +
  scale_x_datetime(name = "",
                   date_labels = "%b",
                   date_breaks = "1 month") +
  theme(legend.position = "bottom") +
  scale_colour_manual(name = "",
                      values = "red") +
  scale_linetype_manual(name = "",
                        values = "dashed")
plt