ggspatial (version 0.2.1)

geom_osm: An Open Street Map Tile Geometry for ggplot2

Description

This geometry is a lazy version of its conterparts in the ggmap and rosm packages. All tile downloading/loading/drawing is done at plot draw, such that a complete backdrop of tiles can be calculated. The arguments are essentially a wrapper around osm.image and annotation_raster that can plot a specific bounding box or default to the extents of the plot. The ggosm() function is a shorthand for the common case of ggplot() + geom_osm(...) + coord_map().

Usage

geom_osm(x = NULL, zoomin = 0, zoom = NULL, type = NULL,
  forcedownload = FALSE, cachedir = NULL, progress = c("text", "none"),
  quiet = TRUE)

ggosm(x = NULL, zoomin = 0, zoom = NULL, type = NULL, forcedownload = FALSE, cachedir = NULL, progress = c("text", "none"), quiet = TRUE)

Arguments

x

An object that can be coerced to a bounding box using extract_bbox, or NULL to use the plot extents to fetch tiles (probably what you want).

zoomin

The amount by which to adjust the automatically calculated zoom (or manually specified if the zoom parameter is passed). Use +1 to zoom in, or -1 to zoom out.

zoom

Manually specify the zoom level (not recommended; adjust zoomin instead.

type

A map type; one of that returned by osm.types. User defined types are possible by passing any object coercible to type tile_source (see as.tile_source).

forcedownload

TRUE if cached tiles should be re-downloaded. Useful if some tiles are corrupted.

cachedir

The directory in which tiles should be cached. Defaults to getwd()/rosm.cache.

progress

A progress bar to use, or "none" to suppress progress updates

quiet

Pass FALSE to see more error messages, particularly if your tiles do not download/load properly.

Value

A ggplot2 layer object

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
library(prettymapr)
# use as a backdrop for geographical data
cities <- geocode(c("Halifax, NS", "Moncton, NB", "Montreal QC"))
ggplot(cities, aes(lon, lat, shape = query)) + geom_osm() +
  geom_point() + coord_map()

# use ggosm() shorthand
ggosm() + geom_point(aes(lon, lat), cities)

# use on its own with a bounding box
ggosm(searchbbox("vermont, USA"))

# use alternative map types (see rosm::osm.types())
ggosm(type = "stamenwatercolor") + geom_point(aes(lon, lat), cities)
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab