{"id":13401367,"url":"https://github.com/ropensci/osmplotr","last_synced_at":"2025-08-20T13:02:36.321Z","repository":{"id":49336633,"uuid":"50378935","full_name":"ropensci/osmplotr","owner":"ropensci","description":"Data visualisation using OpenStreetMap objects","archived":false,"fork":false,"pushed_at":"2025-08-19T12:31:55.000Z","size":34472,"stargazers_count":140,"open_issues_count":15,"forks_count":22,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-08-19T13:30:23.619Z","etag":null,"topics":["data-visualisation","highlighting-clusters","openstreetmap","osm","overpass","overpass-api","peer-reviewed","r","r-package","rstats"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/osmplotr","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2016-01-25T20:31:06.000Z","updated_at":"2025-08-19T12:31:59.000Z","dependencies_parsed_at":"2024-01-29T09:19:14.080Z","dependency_job_id":"6ccc201f-fa97-45b3-b9a0-9997e626ebbe","html_url":"https://github.com/ropensci/osmplotr","commit_stats":{"total_commits":587,"total_committers":9,"mean_commits":65.22222222222223,"dds":0.04940374787052815,"last_synced_commit":"fcc04999f265bec331e25b7a045f727edfa53346"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/ropensci/osmplotr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmplotr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmplotr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmplotr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmplotr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/osmplotr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmplotr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271166351,"owners_count":24710465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-visualisation","highlighting-clusters","openstreetmap","osm","overpass","overpass-api","peer-reviewed","r","r-package","rstats"],"created_at":"2024-07-30T19:01:01.996Z","updated_at":"2025-08-20T13:02:36.280Z","avatar_url":"https://github.com/ropensci.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\ntitle: \"osmplotr, an R package for making maps with OpenStreetMap data\"\nkeywords: \"open street map, openstreetmap, OSM, map, visualisation, visualization\"\noutput:\n  rmarkdown::html_vignette:\n    self_contained: no\n\n  md_document:\n    variant: markdown_github\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r opts, echo = FALSE}\nknitr::opts_chunk$set (\n    collapse = TRUE,\n    warning = TRUE,\n    message = TRUE,\n    width = 120,\n    comment = \"#\u003e\",\n    fig.retina = 2,\n    fig.path = \"README-\"\n)\n```\n\n[![R build\nstatus](https://github.com/ropensci/osmplotr/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/osmplotr/actions?query=workflow%3AR-CMD-check)\n[![codecov](https://app.codecov.io/gh/ropensci/osmplotr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/osmplotr)\n[![Project Status: Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)\n\n![](man/figures/map1.png)\n\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/grand-total/osmplotr?color=orange)](https://cran.r-project.org/package=osmplotr/)\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/osmplotr)](https://cran.r-project.org/package=osmplotr/)\n[![](https://badges.ropensci.org/27_status.svg)](https://github.com/ropensci/software-review/issues/27)\n\nR package to produce visually impressive customisable images of OpenStreetMap\n(OSM) data downloaded internally from the \n[overpass api](http://overpass-api.de/). The above map was produced directly\nfrom `osmplotr` with no further modification. This `README` briefly demonstrates\nthe following functionality:\n\n[1. Quick Introduction](#1 intro)\n\n[2. Installation](#2 installation)\n\n[3. A Simple Map](#3 simple map)\n\n[4. Highlighting Selected Areas](#4 highlighting areas)\n\n[5. Highlighting Clusters](#5 highlighting clusters)\n\n[6. Highlighting Areas Bounded by Named Highways](#6 highlighting with highways)\n\n[7. Data Surfaces](#7 data surfaces)\n\n[8. Gallery](#8 gallery)\n\n---------------\n\n## \u003ca name=\"1 intro\"\u003e\u003c/a\u003e1. Quick Introduction\n\nBut first the easy steps to map making:\n```{r, echo = FALSE, message = FALSE, eval = TRUE}\nlibrary (osmplotr)\n```\n\n\n1. Specify the bounding box for the desired region\n    ```{r}\n    bbox \u003c- get_bbox (c (-0.15, 51.5, -0.10, 51.52))\n    ```\n2. Download the desired data---in this case, all building perimeters.\n    ```{r, eval = FALSE}\n    dat_B \u003c- extract_osm_objects (key = \"building\", bbox = bbox)\n    ```\n3. Initiate an `osm_basemap` with desired background (`bg`) colour\n    ```{r map1, eval = FALSE}\n    map \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\n    ```\n4. Overlay objects on plot in the desired colour.\n    ```{r, eval = FALSE}\n    map \u003c- add_osm_objects (map, dat_B, col = \"gray40\")\n    ```\n5. Print the map to graphics device of choice\n    ```{r, eval = FALSE}\n    print_osm_map (map)\n    ```\n\n```{r london2, echo = FALSE, eval = FALSE}\nlibrary (osmdata)\nbbox \u003c- get_bbox (c (-0.15, 51.5, -0.10, 51.52))\nq0 \u003c- opq (bbox)\nq1 \u003c- add_osm_feature (q0, key = \"building\")\ndat_B \u003c- osmdata_sf (q1, quiet = FALSE)$osm_polygons\nq1 \u003c- add_osm_feature (q0, key = \"highway\")\ndat_H \u003c- osmdata_sf (q1, quiet = FALSE)$osm_lines\nq1 \u003c- add_osm_feature (q0, key = \"leisure\", value = \"park\")\ndat_P \u003c- osmdata_sf (q1, quiet = FALSE)$osm_polygons\nq1 \u003c- add_osm_feature (q0, key = \"landuse\", value = \"grass\")\ndat_G \u003c- osmdata_sf (q1, quiet = FALSE)$osm_polygons\nlondon2 \u003c- list (dat_B = dat_B, dat_H = dat_H, dat_P = dat_P, dat_G = dat_G)\nsave (london2, file = \"london2.rda\")\n```\n\n---------------\n\n## \u003ca name=\"2 installation\"\u003e\u003c/a\u003e2. Installation\n\nFirst install the package\n```{r, eval = FALSE}\ninstall.packages (\"osmplotr\")\n```\nor the development version\n```{r, eval = FALSE}\ndevtools::install_github (\"ropensci/osmplotr\")\n```\nAnd then load it in the usual way\n```{r, eval = FALSE}\nlibrary (osmplotr)\n```\n\n---------------\n\n## \u003ca name=\"3 simple map\"\u003e\u003c/a\u003e3. A Simple Map\n\nSimple maps can be made by overlaying different kinds of OSM data in different\ncolours:\n```{r, eval = FALSE}\ndat_H \u003c- extract_osm_objects (key = \"highway\", bbox = bbox)\ndat_P \u003c- extract_osm_objects (key = \"park\", bbox = bbox)\ndat_G \u003c- extract_osm_objects (key = \"landuse\", value = \"grass\", bbox = bbox)\n```\n```{r, echo = FALSE, eval = FALSE}\nload (\"london2.rda\")\ndat_B \u003c- london2$dat_B\ndat_H \u003c- london2$dat_H\ndat_G \u003c- london2$dat_G\ndat_P \u003c- london2$dat_P\n```\n```{r map2, eval = FALSE}\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\nmap \u003c- add_osm_objects (map, dat_B, col = \"gray40\")\nmap \u003c- add_osm_objects (map, dat_H, col = \"gray80\")\nmap \u003c- add_osm_objects (map, dat_P, col = \"darkseagreen\")\nmap \u003c- add_osm_objects (map, dat_G, col = \"darkseagreen1\")\nprint_osm_map (map)\n```\n```{r map2-print, eval = FALSE, echo = FALSE}\nprint_osm_map (map, file = \"map2.png\", width = 600, units = \"px\", dpi = 72)\n```\n\n\u003c!--\n![](./man/figures/map2.png)\n--\u003e\n\u003cimg src=\"man/figures/map2.png\" width = \"80%\"/\u003e\n\n---------------\n\n## \u003ca name=\"4 highlighting areas\"\u003e\u003c/a\u003e4. Highlighting Selected Areas\n\n`osmplotr` is primarily intended as a data visualisation tool, particularly\nthrough enabling selected regions to be highlighted. Regions can be defined\naccording to simple point boundaries:\n\n```{r}\npts \u003c- sp::SpatialPoints (cbind (\n    c (-0.115, -0.13, -0.13, -0.115),\n    c (51.505, 51.505, 51.515, 51.515)\n))\n```\nOSM objects within the defined regions can then be highlighted with different\ncolour schemes. `cols` defines colours for each group (with only one here),\nwhile `bg` defines the colour of the remaining, background area.\n```{r map3, eval = FALSE}\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\nmap \u003c- add_osm_groups (map, dat_B, groups = pts, cols = \"orange\", bg = \"gray40\")\nmap \u003c- add_osm_objects (map, london$dat_P, col = \"darkseagreen1\")\nmap \u003c- add_osm_groups (\n    map,\n    london$dat_P,\n    groups = pts,\n    cols = \"darkseagreen1\",\n    bg = \"darkseagreen\",\n    boundary = 0\n)\nprint_osm_map (map)\n```\n```{r map3-print, eval = FALSE, echo = FALSE}\nprint_osm_map (map, filename = \"map3.png\", width = 600, units = \"px\", dpi = 72)\n```\n\u003c!--\n![](./man/figures/map3.png)\n--\u003e\n\u003cimg src=\"man/figures/map3.png\" width = \"80%\"/\u003e\n\nNote the `border = 0` argument on the last call divides the park polygons\nprecisely along the border. The same map highlighted in dark-on-light:\n```{r map4, eval = FALSE}\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray95\")\nmap \u003c- add_osm_groups (map, dat_B, groups = pts, cols = \"gray40\", bg = \"gray85\")\nmap \u003c- add_osm_groups (map, dat_H, groups = pts, cols = \"gray20\", bg = \"gray70\")\nprint_osm_map (map)\n```\n```{r map4-print, eval = FALSE, echo = FALSE}\nprint_osm_map (map, filename = \"map4.png\", width = 600, units = \"px\", dpi = 72)\n```\n\u003c!--\n![](./man/figures/map4.png)\n--\u003e\n\u003cimg src=\"man/figures/map4.png\" width = \"80%\"/\u003e\n\n---------------\n\n## \u003ca name=\"5 highlighting clusters\"\u003e\u003c/a\u003e5. Highlighting Clusters\n\n`add_osm_groups` also enables plotting an entire region as a group of\nspatially distinct clusters of defined colours. Groups can be defined by simple\nspatial points denoting their centres:\n\n```{r, echo = TRUE}\nset.seed (2)\nngroups \u003c- 12\nx \u003c- bbox [1, 1] + runif (ngroups) * diff (bbox [1, ])\ny \u003c- bbox [2, 1] + runif (ngroups) * diff (bbox [2, ])\ngroups \u003c- cbind (x, y)\ngroups \u003c- apply (groups, 1, function (i) {\n    sp::SpatialPoints (matrix (i, nrow = 1, ncol = 2))\n})\n```\nCalling `add_osm_groups` with no `bg` argument forces all points lying outside\nthose defined groups to be allocated to the nearest groups, and thus produces an\ninclusive grouping extending across an entire region.\n\n```{r map5, eval = FALSE}\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\nmap \u003c- add_osm_groups (\n    map,\n    dat_B,\n    groups = groups,\n    cols = rainbow (length (groups)),\n    border_width = 2\n)\nprint_osm_map (map)\n```\n```{r map5-print, eval = FALSE, echo = FALSE}\nprint_osm_map (map, filename = \"map5.png\", width = 600, units = \"px\", dpi = 72)\n```\n\u003c!--\n![](./man/figures/map5.png)\n--\u003e\n\u003cimg src=\"man/figures/map5.png\" width = \"80%\"/\u003e\n\n---------------\n\n## \u003ca name=\"6 highlighting with highways\"\u003e\u003c/a\u003e6. Highlighting Areas Bounded by Named Highways\n\nAn alternative way of defining highlighted groups is by naming the highways\nencircling desired regions.\n```{r, eval = FALSE}\n# These highways extend beyond the previous, smaller bbox\nbbox_big \u003c- get_bbox (c (-0.15, 51.5, -0.10, 51.52))\nhighways \u003c- c (\n    \"Davies.St\", \"Berkeley.Sq\", \"Berkeley.St\", \"Piccadilly\",\n    \"Regent.St\", \"Oxford.St\"\n)\nhighways1 \u003c- connect_highways (highways = highways, bbox = bbox_big)\nhighways \u003c- c (\"Regent.St\", \"Oxford.St\", \"Shaftesbury\")\nhighways2 \u003c- connect_highways (highways = highways, bbox = bbox_big)\nhighways \u003c- c (\n    \"Piccadilly\", \"Shaftesbury.Ave\", \"Charing.Cross.R\",\n    \"Saint.Martin\", \"Trafalgar.Sq\", \"Cockspur.St\",\n    \"Pall.Mall\", \"St.James\"\n)\nhighways3 \u003c- connect_highways (highways = highways, bbox = bbox_big)\nhighways \u003c- c (\n    \"Charing.Cross\", \"Duncannon.St\", \"Strand\", \"Aldwych\",\n    \"Kingsway\", \"High.Holborn\", \"Shaftesbury.Ave\"\n)\nhighways4 \u003c- connect_highways (highways = highways, bbox = bbox_big)\nhighways \u003c- c (\n    \"Kingsway\", \"Holborn\", \"Farringdon.St\", \"Strand\",\n    \"Fleet.St\", \"Aldwych\"\n)\nhighways5 \u003c- connect_highways (highways = highways, bbox = bbox_big)\ngroups \u003c- list (highways1, highways2, highways3, highways4, highways5)\n```\nAnd then passing these lists of groups returned by `connect_highways` to\n`add_osm_groups`, this time with some Wes Anderson flair.\n```{r map 6, eval = FALSE}\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\nlibrary (wesanderson)\ncols \u003c- wes_palette (\"Darjeeling\", 5)\nmap \u003c- add_osm_groups (\n    map,\n    dat_B,\n    groups = groups,\n    boundary = 1,\n    cols = cols,\n    bg = \"gray40\",\n    colmat = FALSE\n)\nmap \u003c- add_osm_groups (\n    map,\n    dat_H,\n    groups = groups,\n    boundary = 0,\n    cols = cols,\n    bg = \"gray70\",\n    colmat = FALSE\n)\nprint_osm_map (map)\n```\n```{r map6-print, eval = FALSE, echo = FALSE}\nprint_osm_map (map, filename = \"map6.png\", width = 600, units = \"px\", dpi = 72)\n```\n\u003c!--\n![](./man/figures/map6.png)\n--\u003e\n\u003cimg src=\"man/figures/map6.png\" width = \"80%\"/\u003e\n\n\n---------------\n\n## \u003ca name=\"7 data surfaces\"\u003e\u003c/a\u003e7. Data Surfaces\n\nFinally, `osmplotr` contains a function `add_osm_surface` that spatially\ninterpolates a given set of spatial data points and colours OSM objects\naccording to a specified colour gradient. This is illustrated here with the\n`volcano` data projected onto the `bbox`.\n```{r}\nx \u003c- seq (bbox [1, 1], bbox [1, 2], length.out = dim (volcano) [1])\ny \u003c- seq (bbox [2, 1], bbox [2, 2], length.out = dim (volcano) [2])\nxy \u003c- cbind (rep (x, dim (volcano) [2]), rep (y, each = dim (volcano) [1]))\nz \u003c- as.numeric (volcano)\ndat \u003c- data.frame (x = xy [, 1], y = xy [, 2], z = z)\n```\n```{r map7, eval = FALSE}\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\ncols \u003c- gray (0:50 / 50)\nmap \u003c- add_osm_surface (map, dat_B, dat = dat, cols = cols)\n# Darken cols by ~20%\nmap \u003c- add_osm_surface (\n    map,\n    dat_H,\n    dat = dat,\n    cols = adjust_colours (cols, -0.2)\n)\nmap \u003c- add_colourbar (map, cols = cols, zlims = range (volcano))\nmap \u003c- add_axes (map)\nprint_osm_map (map)\n```\n```{r map7-print, eval = FALSE, echo = FALSE}\nprint_osm_map (map, filename = \"map7.png\", width = 600, units = \"px\", dpi = 72)\n```\n\n```{r map1-print, eval = FALSE, echo = FALSE}\n# This is map1 used as the title\n# extrafont::loadfonts ()\nlab_dat \u003c- data.frame (\n    x = mean (bbox [1, ]), y = mean (bbox [2, ]),\n    lab = \"osmplotr\"\n)\naes \u003c- ggplot2::aes (x, y, label = lab)\n\nbbox \u003c- get_bbox (c (-0.15, 51.5, -0.10, 51.52))\nmap \u003c- osm_basemap (bbox = bbox, bg = \"gray20\")\ncols \u003c- gray (0:50 / 50)\nmap \u003c- add_osm_surface (map, dat_B, dat = dat, cols = cols)\nmap \u003c- add_osm_surface (\n    map,\n    dat_H,\n    dat = dat,\n    cols = adjust_colours (cols, -0.2)\n)\n\n# map2 \u003c- map + ggplot2::geom_text (dat = dat, mapping = aes, size = 60,\n#                                  colour = \"white\",\n#                                 family = \"Lato Light\", nudge_y = 0.0015)\nmap2 \u003c- map + ggplot2::geom_text (\n    dat = lab_dat, mapping = aes, size = 45,\n    colour = \"black\",\n    family = \"Purisa\", fontface = 2,\n    nudge_y = 0.0005, nudge_x = 0.0005\n)\nmap2 \u003c- map2 + ggplot2::geom_text (\n    dat = lab_dat, mapping = aes, size = 45,\n    colour = \"white\", family = \"Purisa\",\n    nudge_y = 0.001, fontface = 2\n)\nprint_osm_map (map2,\n    filename = \"map1.png\", width = 800, units = \"px\",\n    dpi = 72\n)\n```\n\u003c!--\n![](./man/figures/map7.png)\n--\u003e\n\u003cimg src=\"man/figures/map7.png\" width = \"80%\"/\u003e\n\n---------------\n\n## \u003ca name=\"8 gallery\"\u003e\u003c/a\u003e8. Gallery\n\nGot a nice `osmplotr` map? Please contribute in one of the following ways:\n\n1. Fork repo, add link to `README.md/.Rmd`, and send pull request; or\n\n2. Open issue with details; or\n\n3. Send email to address in\n   [`DESCRIPTION`](https://github.com/ropensci/osmplotr/blob/master/DESCRIPTION).\n\n---------------\n\nSee package vignettes \n([basic maps](https://docs.ropensci.org/osmplotr/articles/basic-maps.html) and\n[data maps](https://docs.ropensci.org/osmplotr/articles/data-maps.html)) for a\nlot more detail and further capabilities of `osmplotr`.  Please note that this\nproject is released with a [Contributor Code of\nConduct](https://ropensci.org/code-of-conduct/). By participating in this\nproject you agree to abide by its terms.\n\n--------------\n\n[![ropensci\\_footer](https://ropensci.org//public_images/github_footer.png)](https://ropensci.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fosmplotr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fosmplotr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fosmplotr/lists"}