Learn R Programming

tmap (version 1.2)

map_coloring: Map coloring

Description

Color the polygons of a map such that adjacent polygons have different colors

Usage

map_coloring(x, algorithm = "greedy", ncols = NA, minimize = FALSE,
  palette = NULL, contrast = 1)

Arguments

x
Either a SpatialPolygons(DataFrame) or an adjacency list.
algorithm
currently, only "greedy" is implemented.
ncols
number of colors. By default it is 8 when palette is undefined. Else, it is set to the length of palette
minimize
logical that determines whether algorithm will search for a minimal number of colors. If FALSE, the ncols colors will be picked by a random procedure.
palette
color palette.
contrast
vector of two numbers that determine the range that is used for sequential and diverging palettes (applicable when auto.palette.mapping=TRUE). Both numbers should be between 0 and 1. The first number determines where the palette begins, and t

Value

  • If palette is defined, a vector of colors is returned, otherwise a vector of color indices.

Examples

Run this code
qtm(World, fill="MAP_COLORS", fill.palette="Pastel2")
tm_shape(World) +
  tm_polygons("MAP_COLORS", palette="Pastel2")
data(World, metro)

World$color <- map_coloring(World, palette="Pastel2")
qtm(World, fill = "color")

# map_coloring used indirectly:
qtm(World, fill = "MAP_COLORS")

Run the code above in your browser using DataLab