# Tmap

> R tmap package for thematic maps. Use for publication-quality static and interactive maps.

- Skill: `leolin990405/tmap` (Agent Skill)
- Install (CLI): `npx get-skill add leolin990405/tmap`
- Raw SKILL.md: https://api.skillmd.com/api/skills/leolin990405/tmap/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: LeoLin990405 (https://skillmd.com/u/leolin990405)
- Updated: 2026-11-14
- Page: https://skillmd.com/skills/leolin990405/tmap

---


# tmap Package

Thematic maps with grammar of graphics style.

## Basic Map

```r
library(tmap)
library(sf)

tm_shape(shp) +
  tm_polygons("value")
```

## Map Layers

```r
# Polygons
tm_shape(polygons) +
  tm_polygons("variable",
    style = "quantile",
    palette = "Blues",
    title = "Legend Title"
  )

# Points
tm_shape(points) +
  tm_dots(size = "population", col = "red")

tm_shape(points) +
  tm_bubbles(size = "value", col = "category")

# Lines
tm_shape(roads) +
  tm_lines(col = "type", lwd = 2)

# Raster
tm_shape(raster) +
  tm_raster(palette = "viridis")
```

## Multiple Layers

```r
tm_shape(polygons) +
  tm_polygons("value") +
tm_shape(points) +
  tm_dots(col = "red") +
tm_shape(roads) +
  tm_lines()
```

## Layout

```r
tm_shape(shp) +
  tm_polygons("value") +
  tm_layout(
    title = "Map Title",
    legend.outside = TRUE,
    frame = FALSE
  ) +
  tm_compass(position = c("right", "top")) +
  tm_scale_bar(position = c("left", "bottom")) +
  tm_credits("Source: Data Provider")
```

## Facets

```r
tm_shape(shp) +
  tm_polygons("value") +
  tm_facets(by = "year", ncol = 3)
```

## Interactive Mode

```r
tmap_mode("view")  # Interactive
tmap_mode("plot")  # Static

# Current map interactive
tmap_last() %>% tmap_leaflet()
```

## Save

```r
map <- tm_shape(shp) + tm_polygons()
tmap_save(map, "map.png", width = 1920, height = 1080)
tmap_save(map, "map.html")
```

