R package to produce visually impressive customisable images of OpenStreetMap (OSM) data downloaded internally from the overpass api. The above map was produced directly from
osmplotr with no further modification. This
README briefly demonstrates the following functionality:
But first the easy steps to map making:
Specify the bounding box for the desired region
Download the desired data—in this case, all building perimeters.
osm_basemap with desired background (
Overlay objects on plot in the desired colour.
Print the map to graphics device of choice
First install the package
or the development version
And then load it in the usual way
Simple maps can be made by overlaying different kinds of OSM data in different colours:
osmplotr is primarily intended as a data visualisation tool, particularly through enabling selected regions to be highlighted. Regions can be defined according to simple point boundaries:
OSM objects within the defined regions can then be highlighted with different colour schemes.
cols defines colours for each group (with only one here), while
bg defines the colour of the remaining, background area.
map <- osm_basemap (bbox = bbox, bg = 'gray20') map <- add_osm_groups (map, dat_B, groups = pts, cols = 'orange', bg = 'gray40') map <- add_osm_objects (map, london$dat_P, col = 'darkseagreen1') map <- add_osm_groups (map, london$dat_P, groups = pts, cols = 'darkseagreen1', bg = 'darkseagreen', boundary = 0) print_osm_map (map)
border = 0 argument on the last call divides the park polygons precisely along the border. The same map highlighted in dark-on-light:
add_osm_groups also enables plotting an entire region as a group of spatially distinct clusters of defined colours. Groups can be defined by simple spatial points denoting their centres:
add_osm_groups with no
bg argument forces all points lying outside those defined groups to be allocated to the nearest groups, and thus produces an inclusive grouping extending across an entire region.
An alternative way of defining highlighted groups is by naming the highways encircling desired regions.
# These highways extend beyond the previous, smaller bbox bbox_big <- get_bbox (c(-0.15, 51.5, -0.10, 51.52)) highways <- c ('Davies.St', 'Berkeley.Sq', 'Berkeley.St', 'Piccadilly', 'Regent.St', 'Oxford.St') highways1 <- connect_highways (highways = highways, bbox = bbox_big) highways <- c ('Regent.St', 'Oxford.St', 'Shaftesbury') highways2 <- connect_highways (highways = highways, bbox = bbox_big) highways <- c ('Piccadilly', 'Shaftesbury.Ave', 'Charing.Cross.R', 'Saint.Martin', 'Trafalgar.Sq', 'Cockspur.St', 'Pall.Mall', 'St.James') highways3 <- connect_highways (highways = highways, bbox = bbox_big) highways <- c ('Charing.Cross', 'Duncannon.St', 'Strand', 'Aldwych', 'Kingsway', 'High.Holborn', 'Shaftesbury.Ave') highways4 <- connect_highways (highways = highways, bbox = bbox_big) highways <- c ('Kingsway', 'Holborn', 'Farringdon.St', 'Strand', 'Fleet.St', 'Aldwych') highways5 <- connect_highways (highways = highways, bbox = bbox_big) groups <- list (highways1, highways2, highways3, highways4, highways5)
And then passing these lists of groups returned by
add_osm_groups, this time with some Wes Anderson flair.
map <- osm_basemap (bbox = bbox, bg = 'gray20') library (wesanderson) cols <- wes_palette ('Darjeeling', 5) map <- add_osm_groups (map, dat_B, groups = groups, boundary = 1, cols = cols, bg = 'gray40', colmat = FALSE) map <- add_osm_groups (map, dat_H, groups = groups, boundary = 0, cols = cols, bg = 'gray70', colmat = FALSE) print_osm_map (map)
osmplotr contains a function
add_osm_surface that spatially interpolates a given set of spatial data points and colours OSM objects according to a specified colour gradient. This is illustrated here with the
volcano data projected onto the
map <- osm_basemap (bbox = bbox, bg = 'gray20') cols <- gray (0:50 / 50) map <- add_osm_surface (map, dat_B, dat = dat, cols = cols) # Darken cols by ~20% map <- add_osm_surface (map, dat_H, dat = dat, cols = adjust_colours (cols, -0.2)) map <- add_colourbar (map, cols = cols, zlims = range (volcano)) map <- add_axes (map) print_osm_map (map)
Got a nice
osmplotr map? Please contribute in one of the following ways:
Fork repo, add link to
README.md/.Rmd, and send pull request; or
Open issue with details; or
Send email to address in
See package vignettes (basic maps and data maps) for a lot more detail and further capabilities of
osmplotr. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.