R/map_coloring.R
map_coloring.Rd
Finds colors for every element of a shapefile so that adjacent elements don't have the same color.
map_coloring(shp, min_coloring = TRUE)
an sf object
sf
if TRUE, try to minimize the number of colors used
TRUE
an integer vector of the same length as shp, corresponding to the coloring.
shp
data(oregon) or_short = oregon[30:50, ] map_coloring(or_short) #> [1] 1 3 1 2 1 4 3 2 1 4 3 2 3 2 1 3 3 1 4 2 4 library(ggplot2) ggplot(or_short, aes(fill = map_coloring(or_short))) + geom_sf() + theme_map()