I have a merged dataframe about the affordability ratio (for a specific item), from which I made a plot in ggplot. The years are on the x-axis and the affordability ratio is on the y-axis. The first variable (med. affordability.ratio) is represented through sraight lines and the second one (lower quartile affordability ratio) through dashed lines (by using the geom_line for both variables). I can create a legend for the first variable, but I cannot add a second legend to the graph, which represents the second variable, the dashed lines. Someone an idea? Thanks in advance!
PS: eventually by using the scale_color_manual
function?!
ggplot(affordability.ratio.final, aes
(x=affordability.ratio.final$year,
here`y=affordability.ratio.final$affordability.ratio,
color=affordability.ratio.final$local_authority)) +
labs(title="Affordability Ratios",
x="Year", y = "Affordability Ratio",
color='Local \nAuthority') +
# scale_y_continuous(breaks=c(75000, 100000, 125000, 150000, 175000)
# geom_label_repel(force=15, show.legend = FALSE) +
theme(axis.title=element_text(size="14"),
legend.title=element_text(size="14"),
legend.text=element_text(size="12"),
legend.position="bottom",
axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)),
axis.title.x = element_text(margin = margin(t = 10, r = 0, b = 0, l = 0)),
plot.title = element_text(margin = margin(t = 0, r = 0, b = 10, l = 0))) +
geom_line(data=affordability.ratio.final,
aes(x=affordability.ratio.final$year,
y=affordability.ratio.final$med.affordability.ratio,
group=affordability.ratio.final$local_authority),
size=1) +
geom_line(data=affordability.ratio.final,
aes(x=affordability.ratio.final$year,
y=affordability.ratio.final$lq.affordability.ratio,
group=affordability.ratio.final$local_authority),
size=1, linetype='dashed')