0

I am trying to a graph combining scatter points from original dataset and predicted lines from the model. I want to group and color the scattered point by 3 income quantile and set corresponding color for the predicted lines (Low, medium and high income).

I tried to do that by setting "fill" for the points and "color" for the lines. But for some reason, once I add the scale_color_manual() command line, the points became all black.

colors <- c("Lowest Income Area" = "#00AFBB", "Median Income Area" = "#E7B800", "Highest Income Area" = "#FC4E07")

p <- ggplot() +
  theme_minimal() +
  geom_line(data = new_data,aes(x = x,y = predictions1, color = "Lowest Income Area"), size = 1.5) +
  geom_line(data = new_data,aes(x = x,y = predictions2, color = "Median Income Area"),  size = 1.5) +
  geom_line(data = new_data,aes(x = x,y = predictions3, color = "Highest Income Area"),  size = 1.5) +
  geom_point(data = SBC_bg_df, aes(x = x,y = observed, fill=factor(income_3q)), size = 3) +
  scale_fill_manual(values = colors) +
  scale_colour_manual(breaks=c("Lowest Income Area", "Median Income Area", "Highest Income Area"),
                      values = colors) +
  labs(x = "X", y = "Y", title = "Predicted X over Y", colour = "Predicted", fill="Observed")

p
Rua123
  • 1
  • 1
  • Welcome to SO! One issue is that you map on the `fill` aes but the default shape for geom_point has only a `color` aes. Hence you could try with mapping on the `color` aes, i.e. use `color = factor(income_3q)` or set the shape to one which supports `fill`, e.g. `geom_point(aes(...), shape = 21)`. For more help please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data best shared via `dput()`. – stefan Jun 21 '23 at 20:06

0 Answers0