I have a 60x13 dataframe that contains 4 groups of data, 1 column is time in months 1-60, 1 column is for the median value at timepoint n and 2 for the credible intervals at time point n. I want to produce a plot that has a solid line for the median and dashed lines for the confidence intervals over time, I've been able to do this by adding each column as it's own geom_line and grouping manually by matching the colours of the medians and their corresponding credible intervals, however, I am unable to add a legend. Any help would be appreciated thanks.
ggplot(data=data1,
aes(x=month)) +
xlab("Month") +
ylab("Hazard Ratio") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_line(aes(y=median),
color = "#4682B4",
size = 1) +
geom_line(aes(y=ucrd),
color = "#4682B4",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=lcrd),
color = "#4682B4",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=median.1),
color = "#4BB446",
size = 1) +
geom_line(aes(y=ucrd.1),
color = "#4BB446",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=lcrd.1),
color = "#4BB446",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=median.2),
color = "#AF46B4",
size = 1) +
geom_line(aes(y=ucrd.2),
color = "#AF46B4",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=lcrd.2),
color = "#AF46B4",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=median.3),
color = "#B47846",
size = 1) +
geom_line(aes(y=ucrd.3),
color = "#B47846",
linetype=2,
size = 0.9,
alpha=0.5) +
geom_line(aes(y=lcrd.3),
color = "#B47846",
linetype=2,
size = 0.9,
alpha=0.5)
scale_color_manual(name= "Treament",
values=c("4682B4", "4BB446", "AF46B4", "B47846"),
labels=c("a",
"b",
"c",
"d"
))