library(tidyverse)
library(lubridate)
set.seed(123)
y <- rnorm(100)
df <- tibble(y) %>%
mutate(os = factor(rep_len(1:5, 100)),
date = seq(from = ymd('2013-01-01'), by = 1, length.out = 100))
draw_key_cust <- function(data, params, size) {
if (data$colour %in% c("red", "blue"))
draw_key_vpath(data, params, size)
else
draw_key_path(data, params, size)
}
ggplot(df, aes(x = date, y = y, colour = os)) +
geom_line() +
geom_vline(
aes(xintercept = min(date), linetype = 'os 1'),
colour = 'red', key_glyph = "cust") +
geom_vline(
aes(xintercept = median(date), linetype = 'os 2'),
colour = 'black', key_glyph = "cust") +
geom_hline(
aes(yintercept = 1, linetype = "dashed"),
colour = "blue", key_glyph = "cust"
) +
geom_hline(
aes(yintercept = -1, linetype = "dashed 2"),
colour = "purple", key_glyph = "cust"
) +
scale_linetype_manual(
name = 'lines',
values = c(2, 2, 1, 1),
guide = guide_legend(override.aes = list(colour = c('red', 'black', 'blue', "purple"))))
output:
In the legend, the 2 vertical lines are supposed to be on top while the 2 horizontal lines are supposed to be on the bottom.
How to control that?