9.2 tmap Basics

tmap is a powerful and flexible map-making package with sensible defaults. It has a concise syntax that allows for the creation of attractive maps with minimal code which will be familiar to ggplot2 users.

# tmap can be applied to simples features data
tm_shape(nz)
# at this moment, code produces error: "no layer elements defined after tm_shape"
# Add fill layer to nz shape
tm_shape(nz) +
  tm_fill() 

# Add border layer to nz shape
tm_shape(nz) +
  tm_borders()

# Add fill and border layers to nz shape
tm_shape(nz) +
  tm_fill() +
  tm_borders() 

tm_*() layers include

  • fill
  • borders
  • bubbles
  • text
  • raster
# Bubbles?
tm_shape(nz) +
  tm_bubbles()

More information can be found with help("tmap-element")

9.2.1 Quick Thematic Maps

# wrapper
qtm(nz) # tm_shape(nz) + tm_fill() + tm_borders()

qtm(nz) +
  qtm(nz_height)