I have a plot with two geoms
that I want to separate in the legend
The data:
df <- structure(list(sexo = c("Hombres", "Mujeres", "Ambos sexos",
"Hombres", "Mujeres", "Ambos sexos", "Hombres", "Mujeres", "Ambos sexos",
"Hombres", "Mujeres", "Ambos sexos", "Hombres", "Mujeres", "Ambos sexos"),
ing_t_p = c(615365.502213837, 423714.908007251, 535311.193293098,
627821.976453452, 433415.145738095, 546208.601052767, 664363.627171407,
467060.109828569, 581086.381783187, 685007.895112625, 499376.45299215,
606399.207890318, 704273.922502823, 506650.544840556, 620528.397683238),
se = c(10529.5553778887, 7210.55027509547, 7718.92697284312,
11877.7721047204, 7291.10677673023, 8523.46596771153, 11819.5502743658,
7851.50601614168, 8599.97620004388, 14684.6464451213, 9287.24516124394,
10906.4036899172, 14883.8815328947, 8761.69267167345, 10604.2123276546),
anio = c(2015, 2015, 2015, 2016, 2016, 2016, 2017, 2017, 2017,
2018, 2018, 2018, 2019, 2019, 2019),
brecha = c(-0.31144188862896, -0.31144188862896, -0.31144188862896, -0.309652796503805,
-0.309652796503805, -0.309652796503805, -0.296981215216246, -0.296981215216246, -0.296981215216246, -0.270991682643241, -0.270991682643241, -0.270991682643241,
-0.280605842908339, -0.280605842908339, -0.280605842908339)),
row.names = c(NA, -15L), class = "data.frame")
The plot:
ggplot(df, aes(anio, ing_t_p/1000, fill = factor(sexo, levels = c("Mujeres", "Ambos sexos", "Hombres")))) +
geom_bar(position="dodge", stat="identity") +
geom_point(aes(anio, brecha*-1000), size = 5, colour = "#76A7EF") +
theme(legend.title = element_blank(),
legend.position = "bottom")
The desired legend:
I've tried toying around with theme()
arguments and reviewed the answer given here but I can't seem to make it work. Any help would be gratly appreciated.