ggmap

star 5

R ggmap package for maps with ggplot2. Use for Google Maps and Stamen tiles with ggplot2.

LeoLin990405 By LeoLin990405 schedule Updated 1/30/2026

name: ggmap description: R ggmap package for maps with ggplot2. Use for Google Maps and Stamen tiles with ggplot2.

ggmap Package

ggplot2-style maps with tile backgrounds.

Get Map Tiles

library(ggmap)

# Stamen maps (no API key needed)
map <- get_stadiamap(
  bbox = c(left = -122.5, bottom = 37.5, right = -122, top = 38),
  zoom = 12,
  maptype = "stamen_toner_lite"
)

# Google Maps (requires API key)
register_google(key = "YOUR_API_KEY")
map <- get_googlemap(
  center = c(lon = -122.4, lat = 37.8),
  zoom = 12,
  maptype = "roadmap"
)

Plot Map

ggmap(map)

# With points
ggmap(map) +
  geom_point(data = df, aes(x = lon, y = lat), color = "red", size = 3)

Add Layers

ggmap(map) +
  geom_point(data = df, aes(x = lon, y = lat, color = category)) +
  geom_path(data = route, aes(x = lon, y = lat)) +
  scale_color_viridis_d()

Density Maps

ggmap(map) +
  stat_density_2d(
    data = df,
    aes(x = lon, y = lat, fill = after_stat(level)),
    geom = "polygon",
    alpha = 0.3
  ) +
  scale_fill_viridis_c()

Geocoding

# Google geocoding (requires API)
geocode("1600 Pennsylvania Ave, Washington DC")

# Reverse geocoding
revgeocode(c(-77.0365, 38.8977))

Routes

# Google directions (requires API)
route <- route(
  from = "San Francisco, CA",
  to = "Los Angeles, CA",
  mode = "driving"
)

ggmap(map) +
  geom_path(data = route, aes(x = lon, y = lat), color = "blue", size = 2)

Map Types

# Stadia/Stamen types
"stamen_toner"
"stamen_toner_lite"
"stamen_watercolor"
"stamen_terrain"

# Google types
"roadmap"
"satellite"
"terrain"
"hybrid"
Install via CLI
npx skills add https://github.com/LeoLin990405/r-analytics-skill --skill ggmap
Repository Details
star Stars 5
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
LeoLin990405
LeoLin990405 Explore all skills →