Skip to content
Back to skills

R Spatial

ASecurity

R spatial analysis packages. Use for geographic data, maps, GIS operations, and spatial statistics.

  • 5 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added June 4, 2026
datagogit

Security analysis

A100/100

Pro scans all 20 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-spatial --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Spatial?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Spatial
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-spatial/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-spatial)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-spatial
description: R spatial analysis packages. Use for geographic data, maps, GIS operations, and spatial statistics.
---

# R Spatial Analysis Skill

## Sub-skills

| Sub-skill | Description |
|-----------|-------------|
| [r-spatial-vector](r-spatial-vector/SKILL.md) | sf, sp, terra vectors, geometric operations |
| [r-spatial-raster](r-spatial-raster/SKILL.md) | terra, raster, stars, gridded data |
| [r-spatial-mapping](r-spatial-mapping/SKILL.md) | tmap, leaflet, mapview, ggplot2+sf |

Geographic and spatial data analysis in R.

## Core Spatial Packages

| Package | Description |
|---------|-------------|
| **sf** ★ | Simple Features for R (modern) |
| **terra** ★ | Spatial data analysis (raster/vector) |
| **sp** | Classes for spatial data (legacy) |
| **rgdal** | Geospatial Data Abstraction Library |
| **rgeos** | Geometry Engine - Open Source |

## Mapping & Visualization

| Package | Description |
|---------|-------------|
| **leaflet** ★ | Interactive maps |
| **tmap** ★ | Thematic maps |
| **ggmap** | Maps with ggplot2 |
| **maptools** | Spatial object tools |
| **RColorBrewer** | Color schemes for maps |
| **REmap** | ECharts maps |

## Spatial Statistics

| Package | Description |
|---------|-------------|
| **spatstat** | Spatial point pattern analysis |
| **gstat** | Geostatistical modeling |
| **spdep** | Spatial dependence |
| **GWmodel** | Geographically-weighted models |

## Spatio-temporal

| Package | Description |
|---------|-------------|
| **spacetime** | Spatio-temporal data |

## Data Sources

| Package | Description |
|---------|-------------|
| **tigris** | US Census TIGER shapefiles |
| **rnaturalearth** | Natural Earth map data |
| **osmdata** | OpenStreetMap data |

## Quick Examples

```r
# sf basics
library(sf)

# Read shapefile
shp <- st_read("data.shp")

# Read GeoJSON
geo <- st_read("data.geojson")

# Create from coordinates
points <- st_as_sf(df, coords = c("lon", "lat"), crs = 4326)

# Coordinate reference systems
st_crs(shp)
shp_transformed <- st_transform(shp, crs = 3857)

# Spatial operations
st_intersection(a, b)
st_union(a, b)
st_buffer(points, dist = 1000)
st_area(polygons)
st_distance(a, b)

# Spatial joins
st_join(points, polygons)

# Interactive map with leaflet
library(leaflet)
leaflet(shp) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~colorQuantile("YlOrRd", value)(value),
    weight = 1,
    popup = ~name
  )

# Static map with tmap
library(tmap)
tm_shape(shp) +
  tm_polygons("value",
    style = "quantile",
    palette = "Blues",
    title = "Value"
  ) +
  tm_layout(title = "Map Title")

# ggplot2 + sf
library(ggplot2)
ggplot(shp) +
  geom_sf(aes(fill = value)) +
  scale_fill_viridis_c() +
  theme_minimal()

# Spatial statistics
library(spdep)
# Create neighbors
nb <- poly2nb(shp)
# Spatial weights
lw <- nb2listw(nb)
# Moran's I
moran.test(shp$value, lw)

# Geostatistics
library(gstat)
# Variogram
v <- variogram(value ~ 1, data = points)
plot(v)
# Kriging
v.fit <- fit.variogram(v, vgm("Sph"))
kriged <- krige(value ~ 1, points, grid, v.fit)
```

## Common Workflows

### Choropleth Map
```r
library(sf)
library(tmap)

# Load data
shp <- st_read("boundaries.shp")
data <- read.csv("data.csv")

# Join
shp <- merge(shp, data, by = "id")

# Map
tmap_mode("view")  # Interactive
tm_shape(shp) +
  tm_polygons("value",
    style = "jenks",
    palette = "RdYlBu",
    title = "Value"
  ) +
  tm_borders() +
  tm_layout(legend.outside = TRUE)
```

### Point Pattern Analysis
```r
library(sf)
library(spatstat)

# Convert to ppp
window <- as.owin(boundary)
ppp_obj <- as.ppp(st_coordinates(points), W = window)

# Density
density_map <- density(ppp_obj)
plot(density_map)

# K-function
K <- Kest(ppp_obj)
plot(K)
```

## Resources

- sf: https://r-spatial.github.io/sf/
- terra: https://rspatial.org/
- tmap: https://r-tmap.github.io/tmap/
- leaflet: https://rstudio.github.io/leaflet/
- Geocomputation with R: https://geocompr.robinlovelace.net/

Files in this skill

  • SKILL.md3.9 KB
  • r-spatial-analysis/sp/SKILL.md3.3 KB
  • r-spatial-analysis/spatstat/SKILL.md3.3 KB
  • r-spatial-mapping/SKILL.md1.7 KB
  • r-spatial-mapping/cartography/SKILL.md1.8 KB
  • r-spatial-mapping/ggmap/SKILL.md1.6 KB
  • r-spatial-mapping/mapsf/SKILL.md1.9 KB
  • r-spatial-mapping/mapview/SKILL.md1.4 KB
  • r-spatial-mapping/tmap/SKILL.md1.5 KB
  • r-spatial-raster/SKILL.md1.2 KB
  • r-spatial-raster/raster/SKILL.md1.9 KB
  • r-spatial-raster/stars/SKILL.md1.3 KB
  • r-spatial-raster/terra/SKILL.md1.3 KB
  • r-spatial-vector/SKILL.md1.4 KB
  • r-spatial-vector/maptools/SKILL.md1 KB
  • r-spatial-vector/rgdal/SKILL.md967 B
  • r-spatial-vector/rgeos/SKILL.md1.2 KB
  • r-spatial-vector/sf/SKILL.md2.7 KB
  • sub-skills/r-spatial-mapping/sub-skills/ggmap/SKILL.md1.6 KB
  • sub-skills/r-spatial-mapping/sub-skills/mapview/SKILL.md1.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.