Is there a way in R / ggplot2 of re-ordering the legend to match the it's line position?
So in this example the blue non melanoma skin cancer would be top in the legend.
all_nhs_data <- read_csv("https://www.opendata.nhs.scot/dataset/c2c59eb1-3aff-48d2-9e9c-60ca8605431d/resource/3aef16b7-8af6-4ce0-a90b-8a29d6870014/download/opendata_inc9418_hb.csv")
borders_hb_cncr <- all_nhs_data %>%
filter(HB == "S08000016") %>%
select(CancerSite, Sex, Year, IncidencesAllAges, CrudeRate)
individual_viz <- borders_hb_cncr %>%
filter(CancerSite != "All cancer types") %>%
filter(case_when(
IncidencesAllAges >=50 & Year == 2018 ~ Sex == "All",
TRUE ~ Sex == "All" & IncidencesAllAges >50
)) %>%
ggplot() +
aes(x = Year, y = IncidencesAllAges, group = CancerSite, colour = CancerSite) +
geom_line()