'Problem with creating breaks and setting colors in ggplot maps

I am trying to make a series of maps with the following characteristics:

I want to set bins/colors for tracts$pop.compare as: 0-.75(green), .75-1.25(green), 1.25-2(yellow), 2-3(orange), 3-10(red), 10+(black). I tried the following code, but everything 0-3 is blue, and then 3-10 is yellow, and I'm not sure why that is.

ggplot() + 
  geom_sf(data = tracts, mapping = aes(fill = pop.compare), show.legend = TRUE) +
  scale_fill_stepsn(colours=c("blue", "green", "yellow", "orange", "red", "black"),
                    limits = c(0,227),
                    breaks = c(0.75, 1.25, 2, 3, 10)) + 
  coord_sf()

(also, not all bins are filled. Some are empty and no tract has that value, but I'm doing a series of maps, where they will be filled in other versions, and want to keep the legend / values the same. I tried included drop = FALSE, but got an error for unused argument).

enter image description here

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source