I am trying to code a plot using the data frame 'swiss' from {datasets} using {ggplot2}. I am plotting Infant.Mortality on the x-axis and Fertility on the y-axis, and I want the points to be colored such that they are a transparent blue or orange depending on if they are above or below the median value for Education. However, when I plot, I only get transparent blue points and the legend titles are off.
This is the code I have to far:
swiss$color[swiss$Education >= median(swiss$Education)] <- tBlue
swiss$color[swiss$Education < median(swiss$Education)] <- tOrange
ggplot(data = swiss) +
geom_point(mapping = aes(x = Infant.Mortality, y = Fertility, color = color)) +
scale_color_manual(values = swiss$color,
labels = ">= median", "<median")
I've also tried what was explained in this question (ggplot geom_point() with colors based on specific, discrete values) but I couldn't get it to work.