Description Usage Arguments Value Examples
Color the polygons of a map such that adjacent polygons have different colors
1 2 3 4 5 6 7 8 | map_coloring(
x,
algorithm = "greedy",
ncols = NA,
minimize = FALSE,
palette = NULL,
contrast = 1
)
|
x |
Either a shape (i.e. a |
algorithm |
currently, only "greedy" is implemented. |
ncols |
number of colors. By default it is 8 when |
minimize |
logical that determines whether |
palette |
color palette. |
contrast |
vector of two numbers that determine the range that is used for sequential and diverging palettes (applicable when |
If palette
is defined, a vector of colors is returned, otherwise a vector of color indices.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | if (require(tmap) && packageVersion("tmap") >= "2.0") {
data(World, metro)
World$color <- map_coloring(World, palette="Pastel2")
qtm(World, fill = "color")
# map_coloring used indirectly: qtm(World, fill = "MAP_COLORS")
data(NLD_prov, NLD_muni)
tm_shape(NLD_prov) +
tm_fill("name", legend.show = FALSE) +
tm_shape(NLD_muni) +
tm_polygons("MAP_COLORS", palette="Greys", alpha = .25) +
tm_shape(NLD_prov) +
tm_borders(lwd=2) +
tm_text("name", shadow=TRUE) +
tm_format("NLD", title="Dutch provinces and\nmunicipalities", bg.color="white")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.