Learn R Programming

tmap (version 0.6)

tm_fill: Draw choropleth

Description

This layer speficies a choropleth. A color palette is mapped to a data variable. By default, a divering color palette is used for numeric variables and a qualitative palette for categorical variables.

Usage

tm_fill(col = "grey90", palette = NULL, convert2density = FALSE,
  area = NULL, n = 5, style = "pretty", breaks = NULL, labels = NULL,
  auto.palette.mapping = TRUE, contrast = 1, max.categories = 12,
  colorNA = "grey65", textNA = "Missing", thres.poly = 1e-05)

Arguments

col
either a single color value or a name of the data variable that is contained in shp. In the latter case, a choropleth is drawn.
palette
palette name. See RColorBrewer::display.brewer.all() for options. Use a "-" as prefix to reverse the palette. By default, "RdYlGn" is taken for numeric variables and "Dark2" for categorical variables.
n
preferred number of classes (in case col is a numeric variable)
convert2density
boolean that determines whether col is converted to a density variable. Should be TRUE when col consists of absolute numbers. The area size is either approximated from the shape object, or given by the argument
area
Name of the data variable that contains the area sizes in squared kilometer.
style
method to cut the color scale (in case col is a numeric variable): "fixed", "equal", "pretty", "quantile", "kmeans"
breaks
in case style=="fixed", breaks should be specified
labels
labels of the classes
auto.palette.mapping
When diverging colour palettes are used (i.e. "RdBu") this method automatically maps colors to values such that the middle colors (mostly white or yellow) are assigned to values of 0, and the two sides of the color palette are assigned to negative respect
contrast
number between 0 and 1 (default) that determines the contrast of the palette. Only applicable when auto.palette.mapping=TRUE
max.categories
in case col is the name of a categorical variable, this value determines how many categories (levels) it can have maximally. If the number of levels is higher than max.categories, then levels are combined.
colorNA
color used for missing values
textNA
text used for missing values. Use NA to omit text for missing values in the legend
thres.poly
number that specifies the threshold at which polygons are taken into account. The number itself corresponds to the proportion of the area sizes of the polygons to the total polygon size.

Value

See Also

../doc/tmap-nutshell.html{vignette("tmap-nutshell")}

Examples

Run this code
# World examples
data(World)

tm_shape(World) + tm_fill("green3") + tm_layout_World(title="A green World")

World$highlighted <- ifelse(World$iso_a3 %in% c("GRL", "AUS"), "gold", "gray75")
tm_shape(World, projection="merc") + 
	tm_fill("highlighted") + 
	tm_borders() + 
	tm_layout("Mercator projection. Although used in Google Maps, it is discouraged for
statistical purposes. In reality, Australia is 3 times larger than Greenland!", 
inner.margins=c(0,0,.1,0), title.cex=.6)

tm_shape(World) +
    tm_fill("pop_est_dens", style="kmeans", palette="YlOrRd") +
    tm_borders() +
    tm_text("iso_a3", cex="AREA", cex.lowerbound=.4, bg.alpha=0) +
tm_layout_World(title="Population density per km2")

tm_shape(World) +
    tm_fill("income_grp", palette="-Blues") +
    tm_borders() +
    tm_text("iso_a3", cex="AREA", scale=1.5, bg.alpha=0) +
tm_layout_World("Income classification")

# Europe example
data(Europe)
tm_shape(Europe) +
    tm_fill("gdp_cap_est", style="kmeans", textNA = "Non-European countries") +
    tm_borders() +
    tm_text("iso_a3", cex="AREA", scale=2, bg.alpha=0) +
tm_layout_Europe("GDP per capita")

# Netherlands examples
data(NLD_muni)
data(NLD_prov)

tm_shape(NLD_prov) + 
    tm_fill("name") + 
tm_shape(NLD_muni) + 
    tm_borders() + 
tm_shape(NLD_prov) + 
    tm_borders(lwd=2) +
    tm_text("name") +
tm_layout_NLD("Provinces and municipalities", legend.show=FALSE)

tm_shape(NLD_muni) +
    tm_fill(col="population", convert2density=TRUE, style="kmeans") +
    tm_borders() +
tm_shape(NLD_prov) +
    tm_borders(, lwd=2) +
tm_layout_NLD(title="Population (per km2)", legend.digits=0)

Run the code above in your browser using DataLab