Legend in a dual axis Plot

I'm not able to add a legend to my dual axis line chart. HELPPP

ggplot(Subset_Root_Cat_6_months, aes(x=Date_20_21, y=Covid_Cases_20_21)) +

scale_y_continuous(
name = "First Axis",
sec.axis = sec_axis( trans=~./100, name="Second Axis")
) +
theme_ipsum()+

labs(y= "Overall LOs and COs", x="Date") +
scale_color_manual(name= "Legend", values = c("Overall_LOs_and_COs_20_21"="#4682B4","Overall_LOs_and_COs_19_20"="#CCCCFF","Overall_LOs_and_COs_18_19"="#6495ED","Covid_Cases_20_21"="#69b3a2"))

Value used to transform the data

coeff <- 100

ggplot(Subset_Root_Cat_6_months, aes(x=Date_20_21)) +

geom_line( aes(y=Overall_LOs_and_COs_20_21, color = "LOs+COs 2020"), size=1.3, color="#4682B4") +
scale_x_date(date_labels = "%d-%m", date_breaks = "15 days") +
geom_line( aes(y=Overall_LOs_and_COs_19_20, color = "LOs+COs 2019"), size=1, color="#CCCCFF") +
geom_line( aes(y=Overall_LOs_and_COs_18_19, color = "LOs+COs 2018"), size=1, color="#6495ED") +
geom_line( aes(y=Covid_Cases_20_21 * coeff, color = "Covid Cases 2020"), size=1.3, color="#69b3a2") + # Multiply by 100 to get the same range

scale_y_continuous(

name = "Overall LOs and COs",
sec.axis = sec_axis(~./coeff, name="Covid Cases"))+ 

theme_ipsum()+
ggtitle("Covid Cases and LOs+COs")+

labs(y= "Overall LOs and COs", x="Date") +
scale_color_manual(name= "Legend", values = c("Overall_LOs_and_COs_20_21"="#4682B4","Overall_LOs_and_COs_19_20"="#CCCCFF","Overall_LOs_and_COs_18_19"="#6495ED","Covid_Cases_20_21"="#69b3a2"))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.