so I have a two Y-Axis plot. Each Y-Axis is given a group of Data.
I want to have two different legends for each group on left and right side of plot on the locations shown in the second picture.
This is the code I am using:
coeff <- .025
Plot <- ggplot(df_visual_count_average, aes(x=cym)) +
geom_line(aes(y = count_cont_res, color = "Count Cat1"), group = 1, size = 1.5) +
geom_line(aes(y = count_fos_car, color = "Count Cat2"), group = 2, size = 1.5 ) +
geom_line(aes(y = count_oth, color = "Count Cat3"), group = 3, size = 1.5) +
geom_line(aes(y = count_SHSS_cont_res, color = "Count Cat4"), group = 4, size = 1.5) +
geom_line(aes(y = ave_age_cont_res/coeff, color = "Ave age of Cat5"), group = 1, size = 1.5) +
geom_line(aes(y = ave_age_fos_car/coeff, color = "Ave age of Cat6"), group = 2, size = 1.5 ) +
geom_line(aes(y = ave_age_oth/coeff, color = "Ave age Cat7"), group = 3, size = 1.5) +
geom_line(aes(y = ave_age_SHSS_cont_res/coeff, color = "Ave age Cat8"), group = 4, size = 1.5) +
scale_y_continuous( name = "Counts of Group1", sec.axis = sec_axis(~.*coeff, name="Average of Group 2") ) +
ggtitle("Counts and Average of Group variation with time")
Plot
The first pic is the current plot I am having and the later plot is the one I want to update to: