Introduction to tmap

Visualizing Geospatial Data in R

Charlotte Wickham

Assistant Professor at Oregon State University

tmap displays spatial data

  • Similar philosophy to ggplot2:
    • A plot is built up in layers
    • ggplot2 expects data in data frames, tmap expects data in spatial objects
    • Layers consist of a type of graphical representation and mapping from visual properties to variables
Visualizing Geospatial Data in R

Building a plot in layers

library(tmap)
data(Europe)

tm_shape(Europe) +
tm_borders()

tmap.png

Visualizing Geospatial Data in R

Building a plot in layers

library(tmap)
data(Europe)

tm_shape(Europe) +
tm_borders() + tm_fill(col = "part")
  • tm_fill()
  • tm_borders()
  • tm_polygons()
  • tm_bubbles()
  • tm_dots()
  • tm_lines()
  • tm_raster()
  • tm_text()
Visualizing Geospatial Data in R

Building a plot in layers

library(tmap)
data(Europe)

tm_shape(Europe) +
tm_borders() + tm_fill(col = "part") + tm_compass() + tmap_style("cobalt")

tmap2.png

Visualizing Geospatial Data in R

Key differences to ggplot2

  • No scale_ equivalents, tweaks to scales happen in relevant layer call
  • tm_shape() defines default data for any subsequent layers, you can have many in a single plot
  • No need for x and y aesthetics, these are inherent in spatial objects
  • No special evaluation, when mapping variables they must be quoted
Visualizing Geospatial Data in R

Let's practice!

Visualizing Geospatial Data in R

Preparing Video For Download...