I have below ggplot:
library(ggplot2)
library(quantmod)
Val1 = rnorm(10, 10, 1)
Data1 = data.frame('Name' = 'Name1', 'Date' = as.yearqtr(rep(seq(as.Date('2002-01-01'), length.out = 10, by = '95 day'), 3)), val = Val1, val_low = Val1 - 10, val_up = Val1 + 10)
Val2 = rnorm(10, 20, 1)
Data2 = data.frame('Name' = 'Name2', 'Date' = as.yearqtr(rep(seq(as.Date('2002-01-01'), length.out = 10, by = '95 day'), 3)), val = Val2, val_low = Val2 - 10, val_up = Val2 + 10)
Data = rbind(Data1, Data2)
ggplot() +
geom_line(data = Data1, mapping = aes(x=Date, y=val), color = '#ffb703', linetype='solid') +
geom_line(data = Data2, mapping = aes(x=Date, y=val),color = 'green', linetype='solid')
With this, I can generate below plot:
While this is fine, but I want to create custom legend for Name1 & Name2 with respective colours. I also want that legend to be placed in top middle position.
Is there any way to achieve this?