I'm trying to make a scatter plot with overlapping subsets of data. I'm successful to produce the plot but I'm struggling with placing the legend. In this dataset, I want to give different colors and shapes for points matching with covid-19 and the Russia-Ukraine War.
df %>%
ggplot(aes(x=CovidAid, y=FoodInflation)) +
geom_point() +
geom_point(data = df %>% filter(Covid=="COVID"), pch=24, size=3, color="red") +
geom_point(data = df %>% filter(War=="War"), pch=25, size=3, color="red") +
labs(y="Food Inflation", x="COVID-19 Assistance, million USD") +
scale_y_continuous(labels = scales::percent, breaks = seq(-0.01,0.12,0.02)) +
theme_bw() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.text = element_text(color = "black"), axis.title = element_text(face = "bold"),
legend.position = "bottom", legend.justification = "center", legend.direction = "horizontal")
I tried scale_color_manual() and scale_shape_manual() by putting values for those three categories but didn't work.