rcityviews
rcityviews is a user-friendly R interface for creating stylized city maps using OpenStreetMap (www.openstreetmap.org) data, implemented as an R package and a Shiny web application.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.7%) to scientific vocabulary
Keywords
Repository
rcityviews is a user-friendly R interface for creating stylized city maps using OpenStreetMap (www.openstreetmap.org) data, implemented as an R package and a Shiny web application.
Basic Info
- Host: GitHub
- Owner: koenderks
- License: gpl-3.0
- Language: R
- Default Branch: development
- Homepage: https://koenderks.github.io/rcityviews/
- Size: 1.23 GB
Statistics
- Stars: 193
- Watchers: 5
- Forks: 24
- Open Issues: 2
- Releases: 4
Topics
Metadata Files
README.md
R City Views

This repository is an homage to the programming language R, open-source
geographic data and the art of map making. It provides code and examples to
render customizable stylized city maps using data from
OpenStreetMap. Take a look at the
tutorial for
a quick guide on how to get started.
Every three hours this repository creates and tweets a view of a random city.
You can find all city views created so far at the twitter handle
@rcityviews. Please do not hesitate to share
your own creations using the hashtag #rcityviews!
Installation
The functionality in this repository is implemented in the R package
rcityviews. This package is not available on CRAN but can be obtained via
GitHub by running the command below in R.
```r
install.packages("remotes") # Uncomment if 'remotes' package is not installed
remotes::install_github("koenderks/rcityviews", dependencies = TRUE) ```
After installation, you can load the package into the R session using the
following command.
r
library(rcityviews)
Create your own in R
Finding a city to map
First, you can search for a city name in the package database using the
list_cities() function. This function looks in the internal database and finds
any city name that contains the expression in match. It returns a
data.frame, so you can select a specific city by its row index (i.e.,
[rowIndex, ]).
```r list_cities(match = "Ams")
> name country lat long
> 1356 Amstelveen The Netherlands 52.32 4.86
> 1357 Amsterdam The Netherlands 52.37 4.89
> 1358 Amstetten Austria 48.13 14.86
> 25857 New Amsterdam Guyana 6.25 -57.53
> 26031 Nieuw Amsterdam Suriname 5.91 -55.07
city <- list_cities(match = "Ams")[2, ] # Select Amsterdam ```
If you cannot find your preferred city in the internal package database but know
its coordinates, you can use the new_city() function to manually specify the
location using the latitude (lat)and longitude (long) arguments.
```r city <- new_city(name = "Lagos", country = "Portugal", lat = 37.10, long = -8.68)
> Discovered Lagos, Portugal at 37.1 / -8.68!
```
Alternatively, if you don't know the exact coordinates of your city, you can
leave the lat and long arguments empty, and the new_city() function will
automatically attempt to find the coordinates using geocoding.
```r city <- new_city(name = "Coober Pedy", country = "Australia")
> Discovered Coober Pedy, Australia at -29.0133682 / 134.7536164!
```
Creating the map
Second, once you have obtained the name of the city you want to view or have
specified a location of a city, you can use the cityview() function to create
a ggplot2 object. Use the zoom argument to zoom in on your city (e.g.,
zoom > 1, decreases computation time) or zoom out of your city (e.g.,
zoom < 0.5, increases computation time). By default, cityview() is called
with the cache = TRUE flag, which means that it will cache the map data so
that you can quickly try out different themes (see below).
```r p <- cityview(name = "Amsterdam", zoom = 1) # or cityview(name = city)
see ?cityview for more input parameters of this function
```
Saving the map
Finally, render times in R or RStudio can be very long for crowded spatial
images. It is therefore recommended to directly save the image in a
500mm x 500mm format. Typically, the ideal way to do this given a ggplot2
object named p is to execute the command below.
r
ggplot2::ggsave(filename = "Amsterdam.png", plot = p, height = 500, width = 500, units = "mm", dpi = 100)
However, you can also do this instantly by providing a filename directly to the
cityview() function via its filename argument. To save rendering time, the
image is exported in an appropriate size and the function does not return a
ggplot2 object.
r
cityview(name = "Amsterdam", filename = "Amsterdam.png")
For personal (non-commercial) printing it is advised to use the option
license = FALSE and save the image to a .pdf or .svg file. Afterwards, the
image is best printed in a 500mm x 500mm format.
Styling the map
There are ten pre-specified themes that can be used to style the image. The
image above is created using theme = "vintage" (the default), but other
options for the theme argument include modern (top left), bright (top
middle), delftware (top right), comic (middle left), rouge (middle
middle), original (middle right), midearth (bottom left), batik (bottom
middle) and vice (bottom right).
In addition to the ten pre-specified themes, the package provides full flexibility to customize the theme by providing a named list. This is demonstrated in the code block below.
```r
For example: black, beige and white theme, streets only
myTheme <- list( colors = list( background = "#232323", water = "#232323", landuse = "#232323", contours = "#232323", streets = "#d7b174", rails = c("#d7b174", "#232323"), buildings = "#232323", text = "#ffffff", waterlines = "#232323" ), font = list( family = "serif", face = "bold", scale = 1, append = "\u2014" ), size = list( borders = list( contours = 0.15, water = 0.4, canal = 0.5, river = 0.6 ), streets = list( path = 0.2, residential = 0.3, structure = 0.35, tertiary = 0.4, secondary = 0.5, primary = 0.6, motorway = 0.8, rails = 0.65, runway = 3 ) ) ) cityview(name = "Rio de Janeiro", zoom = 0.5, theme = myTheme, border = "square", filename = "Rio.png") ```
You can store the custom theme in the package cache for retrieval in a future R
session with the city_themes() function. This is illustrated below for
the myTheme list.
```r
Store the theme in the persistent cache
city_themes(name = "blackyellow", theme = myTheme)
Retreive the theme from the persistent cache (e.g., in a future R session)
city_themes(name = "blackyellow")
Remove the theme from the persistent cache
city_themes(name = "blackyellow", remove = TRUE) ```
To use a custom font in myTheme[["font"]][["family"]], simply donwload a
.ttf file of the font from the web, save it as path/to/font/<font_name>.ttf
and register the font via the code below. Then, use <font_name> for family.
r
sysfonts::font_add("<font_name>", "path/to/font/<font_name>.ttf")
Enclosing the map
There are several types of borders that can be used to enclose the city. The
image above is created using border = "square", but other options for the
border argument include none (the default), circle (left), rhombus
(middle), square, hexagon, octagon, decagon and bbox (right).
Other display options
There are three other arguments to the cityview() function that can be used to
tailor the image to your liking. First, the argument halftone allows you to
add a colored dotted dither to the image (e.g., halftone = "#ffffff", left).
Second, setting legend = TRUE adds a distance measurer and a compass to the
image (middle). Third, the argument places takes an integer and adds that
amount of names of towns, villages, suburbs, quarters and neighbourhoods to the
image (e.g., places = 10, right).
Create your own in Shiny
You can make your own images without having to code using an R Shiny
implementation of the package. A live version of the application can be found
here but it is also easily
accessible from within R by calling the function cityview_shiny().
Acknowledgements
The data is available under the Open Database License.
Owner
- Name: Koen Derks
- Login: koenderks
- Kind: user
- Location: Amsterdam
- Company: Nyenrode Business University
- Website: https://koenderks.com
- Twitter: koenderks
- Repositories: 9
- Profile: https://github.com/koenderks
Assistant Professor at Nyenrode Business University & Developer at JASP (www.jasp-stats.org), free and open-source statistical software.
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 24
- Total pull requests: 7
- Average time to close issues: about 1 month
- Average time to close pull requests: about 14 hours
- Total issue authors: 18
- Total pull request authors: 5
- Average comments per issue: 3.33
- Average comments per pull request: 1.86
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 5
- Pull requests: 6
- Average time to close issues: about 5 hours
- Average time to close pull requests: about 14 hours
- Issue authors: 4
- Pull request authors: 4
- Average comments per issue: 5.8
- Average comments per pull request: 2.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- stalkerGH (5)
- pokyah (2)
- SpatLyu (2)
- Heed725 (1)
- szimmer (1)
- bekirburakcelik (1)
- emmaklugman (1)
- AlexINSERM (1)
- KlausVigo (1)
- lluisvicens (1)
- kai-lim (1)
- ytakemon (1)
- rafabelokurows (1)
- mantaluke (1)
- koenderks (1)
Pull Request Authors
- koenderks (4)
- pokyah (3)
- lopezrj (2)
- SpatLyu (2)
- KlausVigo (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
proxy.golang.org: github.com/koenderks/rcityviews
- Documentation: https://pkg.go.dev/github.com/koenderks/rcityviews#section-documentation
- License: gpl-3.0
-
Latest release: v1.0.2
published over 3 years ago
Rankings
Dependencies
- R >= 2.10 depends
- cowplot * imports
- geosphere * imports
- ggplot2 * imports
- ggspatial * imports
- osmdata * imports
- progress * imports
- sf * imports
- showtext * imports
- sysfonts * imports
- utils * imports
- testthat * suggests
- Mattraks/delete-workflow-runs v2 composite
- actions/checkout v2 composite
- ad-m/github-push-action master composite
- r-lib/actions/setup-r v2 composite
- actions/cache v1 composite
- actions/checkout v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- actions/checkout v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite