How to reverse color gradient when using geom_sf?



When creating a choropleth map of an sf object with ggplot2, the default color gradient assigns the darker color to the smaller number:

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
  geom_sf(aes(fill = AREA))

I'd like to reverse that so the darker color is assigned to the larger number. I thought this should work but it doesn't:

ggplot(nc) +
  geom_sf(aes(fill = AREA)) +
  scale_colour_gradient(low = "#56B1F7", high = "#132B43")

Any suggestions on what I'm doing wrong? Thanks.


Oops never mind, that should be

ggplot(nc) +
  geom_sf(aes(fill = AREA)) +
  scale_fill_gradient(low = "#56B1F7", high = "#132B43")


If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: