cartography

star 5

R cartography package for thematic mapping. Use for creating publication-quality thematic maps.

LeoLin990405 By LeoLin990405 schedule Updated 1/30/2026

name: cartography description: R cartography package for thematic mapping. Use for creating publication-quality thematic maps.

cartography

Thematic cartography.

Basic Map

library(cartography)
library(sf)

# Read data
mtq <- st_read(system.file("gpkg/mtq.gpkg", package = "cartography"))

# Plot base map
plot(st_geometry(mtq), col = "lightblue", border = "white")

Choropleth Map

# Choropleth
choroLayer(
  x = mtq,
  var = "MED",
  method = "quantile",
  nclass = 5,
  col = carto.pal("green.pal", 5),
  border = "white",
  legend.title.txt = "Median Income"
)

Proportional Symbols

# Proportional circles
propSymbolsLayer(
  x = mtq,
  var = "POP",
  col = "red",
  border = "white",
  legend.title.txt = "Population"
)

# Proportional + choropleth
propSymbolsChoroLayer(
  x = mtq,
  var = "POP",
  var2 = "MED",
  col = carto.pal("blue.pal", 4)
)

Typology Map

# Categorical map
typoLayer(
  x = mtq,
  var = "STATUS",
  col = carto.pal("pastel.pal", 4),
  legend.title.txt = "Status"
)

Labels

# Add labels
labelLayer(
  x = mtq,
  txt = "LIBGEO",
  col = "black",
  cex = 0.7,
  halo = TRUE
)

Layout Elements

# Title
layoutLayer(
  title = "Map Title",
  author = "Author",
  sources = "Data source",
  scale = 5,
  north = TRUE
)

# North arrow
north(pos = "topleft")

# Scale bar
barscale(size = 5)

Color Palettes

# Available palettes
display.carto.all()

# Get palette
carto.pal("green.pal", 5)
carto.pal("red.pal", 7)
carto.pal("blue.pal", 4)
carto.pal("orange.pal", 6)

Smoothed Map

# Kernel density
smoothLayer(
  x = mtq,
  var = "POP",
  typefct = "exponential",
  span = 3000,
  beta = 2
)

Links/Flows

# Flow map
gradLinkLayer(
  x = links,
  df = flow_data,
  xid = "origin",
  yid = "destination",
  var = "flow"
)
Install via CLI
npx skills add https://github.com/LeoLin990405/r-analytics-skill --skill cartography
Repository Details
star Stars 5
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
LeoLin990405
LeoLin990405 Explore all skills →