Content
- Choropleth Mapping with in R
- Type of choropleth map
- Choosing number of classes
- Data classification methods
- Selecting colour scheme
- tmap Methods
- tmap framewok
- tmap elements
- tmap layers
- tmap layout
- tmap style
- tmap facet
School of Computing and Information Systems,
Singapore Management University
21 Feb 2023
A choropleth map is a type of thematic map in which areas are shaded or patterned in proportion to a statistical variable that represents an aggregate summary of a geographic characteristic within each area, such as population or per-capita income.
Two approaches can be used to prepare thematic map using tmap, they are:
Plotting a thematic map quickly by using qtm()
.
Plotting highly customisable thematic map by using tmap elements.
qtm()
The easiest and quickest to draw a choropleth map using tmap is using qtm()
. It is concise and provides a good default visualisation in many cases.
tmap_mode()
with “plot” option is used to produce a static map. For interactive mode, “view” option should be used.
fill
argument is used to map the attribute (i.e. DEPENDENCY)
tm_shape()
tm_shape()
, which specifies the shape object.tm_polygons()
, tm_symbols()
, tm_lines()
, tm_raster()
and tm_text()
Each aesthetic can take a constant value or a data variable name. For instance, tm_fill(col="blue")
colors all polygons blue, while tm_fill(col="var1")
, where “var1” is the name of a data variable in the shape object, creates a choropleth.
The supported derived layers are as follows:
tm_fill()
and tm_border()
tm_border()
Choropleth maps on the left and right below show quantile and equal data classification methods are used.
Map layout refers to the combination of all map elements into a cohensive map.
In tmap, several legend options are provided to change the placement, format and appearance of the legend.
tm_shape(mpszpop2020)+
tm_fill("DEPENDENCY",
style = "jenks",
palette = "Blues",
legend.hist = TRUE,
legend.is.portrait = TRUE,
legend.hist.z = 0.1) +
tm_layout(main.title = "Distribution of Dependency Ratio by planning subzone \n(Jenks classification)",
main.title.position = "center",
main.title.size = 1,
legend.height = 0.45,
legend.width = 0.35,
legend.outside = FALSE,
legend.position = c("right", "bottom"),
frame = FALSE) +
tm_borders(alpha = 0.5)
Beside map style, tmap also also provides arguments to draw other map furniture such as compass, scale bar and grid lines. In the choropleth below, tm_compass()
, tm_scale_bar()
and tm_grid()
are used to add compass, scale bar and grid lines onto the choropleth map.
tm_shape(mpszpop2020)+
tm_fill("DEPENDENCY",
style = "quantile",
palette = "Blues",
title = "No. of persons") +
tm_layout(main.title = "Distribution of Dependency Ratio \nby planning subzone",
main.title.position = "center",
main.title.size = 1.2,
legend.height = 0.45,
legend.width = 0.35,
frame = TRUE) +
tm_borders(alpha = 0.5) +
tm_compass(type="8star", size = 2) +
tm_scale_bar(width = 0.15) +
tm_grid(lwd = 0.1, alpha = 0.2) +
tm_credits("Source: Planning Sub-zone boundary from Urban Redevelopment Authorithy (URA)\n and Population data from Department of Statistics DOS",
position = c("left", "bottom"))
Small multiple maps, also refered to facet maps, are composed of many maps arrange side-by-side, and sometimes stacked vertically. Small multiple maps enable the visualisation of how spatial relationships change with respect to another variable, such as time.
In tmap, small multiple maps can be plotted in three ways:
In this example, small multiple choropleth maps are created by defining ncols in tm_fill()
.
In this example, small multiple choropleth maps are created by assigning multiple values to at least one of the aesthetic arguments
tmap_arrange()
In this example, multiple small choropleth maps are created by creating multiple stand-alone maps with tmap_arrange()
.
tm_facets()
In this example, multiple small choropleth maps are created by using tm_facets()
.
Instead of creating small multiple choropleth map, you can also use selection function to map spatial objects meeting the selection criterion.
tm_shape(mpszpop2020
[mpszpop2020$REGION_N=="CENTRAL REGION", ]) +
tm_fill("DEPENDENCY",
style = "quantile",
palette = "Blues",
legend.hist = TRUE,
legend.is.portrait = TRUE,
legend.hist.z = 0.1) +
tm_layout(legend.outside = TRUE,
legend.height = 0.45,
legend.width = 5.0,
legend.position = c("right",
"bottom"),
frame = FALSE) +
tm_borders(alpha = 0.5)
Core Reading
Additional Readings