ggmap v2.6.1

0

Monthly downloads

0th

Percentile

by David Kahle

Spatial Visualization with ggplot2

A collection of functions to visualize spatial data and models on top of static maps from various online sources (e.g Google Maps and Stamen Maps). It includes tools common to those tasks, including functions for geolocation and routing.

Readme

ggmap

ggmap makes it easy to retrieve raster map tiles from popular online mapping services like Google Maps, OpenStreetMap, Stamen Maps, and plot them using the ggplot2 framework:

library(ggmap)

us <- c(left = -125, bottom = 25.75, right = -67, top = 49)
map <- get_stamenmap(us, zoom = 5, maptype = "toner-lite")
ggmap(map)

ggmap(map, extent = "device")

Use qmplot() in the same way you'd use qplot(), but with a map automatically added in the background:

downtown <- subset(crime,
  -95.39681 <= lon & lon <= -95.34188 &
   29.73631 <= lat & lat <=  29.78400
)

qmplot(lon, lat, data = downtown, maptype = "toner-background", color = I("red"))

qmplot(lon, lat, data = downtown, maptype = "toner-lite", geom = "density2d", color = I("red"))

Since ggmap's built on top of ggplot2, all your usual ggplot2 stuff (geoms, polishing, etc.) will work, and there are some unique graphing perks ggmap brings to the table, too.

robberies <- subset(downtown, offense == "robbery")

qmplot(lon, lat, data = downtown, geom = "blank", zoom = 15, maptype = "toner-background", darken = .7) +
  stat_density_2d(aes(fill = ..level..), geom = "polygon", alpha = .3, color = NA) +
  scale_fill_gradient2("Robbery\nPropensity", low = "white", mid = "yellow", high = "red", midpoint = 1500)

Faceting works, too:

qmplot(lon, lat, data = downtown, maptype = "toner-background", color = offense) + 
  facet_wrap(~ offense)

For convenience, here's a map of Europe:

europe <- c(left = -12, bottom = 35, right = 30, top = 63)
map <- get_stamenmap(europe, zoom = 5, maptype = "toner-lite")
ggmap(map)

Installation

  • From CRAN: install.packages("ggmap")

  • From Github: devtools::install_github("dkahle/ggmap")

Functions in ggmap

Name Description
XY2LonLat Convert a tile coordinate to a lon/lat coordinate
inset Add ggplot2 insets to a map
hadley Highly unofficial ggplot2 image
OSM_scale_lookup Look up OpenStreetMap scale for a given zoom level.
LonLat2XY Convert a lon/lat coordinate to a tile coordinate
theme_inset Make a ggplot2 inset theme.
print.ggmap Print a map
get_openstreetmap Get an OpenStreetMap
route Grab a route from Google
geocode Geocode
ggmapplot Don't use this function, use ggmap.
legs2route Convert a leg-structured route to a route-structured route
mapdist Compute map distances using Google
calc_zoom Calculate a zoom given a bounding box
revgeocode Reverse geocode
theme_nothing Make a blank ggplot2 theme.
get_map Grab a map.
get_googlemap Get a Google Map.
ggimage Plot an image using ggplot2
qmplot Quick map plot
inset_raster Create a (ggplot2) raster layer
bb2bbox Convert a bb specification to a bbox specification
qmap Quick map plot
get_stamenmap Get a Stamen Map
gglocator Locator for ggplots.
wind Wind data from Hurricane Ike
file_drawer Manage the ggmap file drawer.
crime Crime data
get_cloudmademap Get a CloudMade map.
make_bbox Compute a bounding box
mutate_geocode Geocode a dataset
get_navermap Get a Naver Map
distQueryCheck Check Google Maps Distance Matrix API query limit
geom_leg Single line segments with rounded ends
ggmap Plot a ggmap object
routeQueryCheck Check Google Maps Directions API query limit
zips Zip code data for the Greater Houston Metropolitan Area from the 2000 census
No Results!

Last month downloads

Details

URL https://github.com/dkahle/ggmap
BugReports https://github.com/dkahle/ggmap/issues
License GPL-2
LazyData true
RoxygenNote 5.0.1
NeedsCompilation no
Packaged 2016-01-22 15:39:39 UTC; david_kahle
Repository CRAN
Date/Publication 2016-01-23 00:37:27

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/ggmap)](http://www.rdocumentation.org/packages/ggmap)