Lesson 1:
GeoVisualisation and Analytical Mapping:
tmap Methods

Dr. Kam Tin Seong
Assoc. Professor of Information Systems(Practice)

School of Computing and Information Systems,
Singapore Management University

13 Nov 2023

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

Choropleth Map

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.

Classified choropleth map

  • Choropleth maps can be either classified or unclassified.
  • A classed choropleth map combines areal units into a smaller number of groups. Interval levels may vary, but typically 4 to 7 are used in a map. There is different classification techniques used to divide up the intervals.

Unclassified choropleth map

  • Unclassed choropleth maps are similar to classed choropleth maps; however, unclassed choropleth maps do not have an averaged statistic towards each particular colour.

Choosing an appropriate number of classes

Data classification

Methods of choosing classes

  • Based on the nature of the distribution
    • quantile, equal interval, natural breaks, standard deviations, defined interval
  • Arbitrary
    • Can be based on round numbers.
    • Examples: Grouping according to age or census housing categories
    • Can result in empty categories

Data classification method: Quantile

  • Same number of features per class.

Data classification method: Equal interval

  • Divides the range of attribute values into equally sized classes.

Caution

Avoid equal interval if your data are skewed to one end or if you have one or two really large outlier values. Outliers in that case will likely produce empty classes, wasting perfectly good classes with no observations in them. Since the hotel data above doesn’t have really large outliers, this is a data distribution that works well with equal interval.

Data classification method: Jenks (also known as Natural breaks)

  • Default Jenk’s statistical optimization
  • Finds natural groupings in the data

Data classification: Standard deviation

  • A measure of dispersion.
  • Use if the distribution approximates a normal distribution (bell-shaped curve)

Colour scheme

ColorBrewer

Mapping packages in R

CRAN Task View: Analysis of Spatial Data

Other packages

Introducing tmap

  • tmap is a R package specially designed for creating thematic maps using the pricinples of the Grammar of Graphics.
  • It offers a flexible, layer-based, and easy to use approach to create thematic maps, such as choropleths and proportional symbol maps.
  • It supports two modes: plot(static maps) and view (interactive maps).
  • It provides shiny integration(with tmapOutput and renderTmap).

Shape objects

  • tmap supports simple features from the new sf package.
  • It also supports the class Spatial and Raster, respectively from the sp and the raster package. The supported subclasses are:

Plotting functions of tmap

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.

Plotting a choropleth map quickly by using 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)

tmap_mode("plot")
qtm(mpszpop2020, 
    fill = "DEPENDENCY")

tmap elements

tm_shape()

  • The first element to start with is tm_shape(), which specifies the shape object.

tmap elements

Base layers

  • Next, one, or a combination of the following drawing layers should be specified:

tmap elements

Base layers

  • Each of these functions specifies the geometry, mapping, and scaling component of the LGTM.
  • An aesthetic can take a constant value, a data variable name, or a vector consisting of values or variable names.
  • If a data variable is provided, the scale is automatically configured according to the values of this variable, but can be adjusted with several arguments. For instance, the main scaling arguments for a color aesthetic are color palette, the preferred number of classes, and a style to create classes.
  • Also, for each aesthetic, except for the text labels, a legend is automatically created.
  • If a vector of variable names is provided, small multiples are created, which will be explained further below.

tmap elements

Derived layers

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:

Reference

Principles, Concepts and Methods of Choropleth Maps Design

Core Reading

Additional Readings

References

All About tmap package