How to create a city map in RStudio with "rcityviews"
Posted on February 24, 2023 • 2 minutes • 268 words
Table of contents
How to create a city map in RStudio: “rcityviews”
R City Views is a package developed by Koen Derks who is an Assistant Professor at Nyenrode Business University. It allows to create maps from OpenStreetMap in R. Official documentation for rcityviews is available here. There is also a Twitter account .
Firstly, the package should be installed and remotes
package can be a prerequisite.
install.packages("remotes")
After that this code will install the package from its github repository.
remotes::install_github("koenderks/rcityviews", dependencies = TRUE)
Then load it into the Rstudio:
library(rcityviews)
After loading, this code will import more than 43K city coordinates and population info as a data frame into the environment:
data(cities)
After loading the city data, this code will import data from OpenStreetMap for Vienna, Austria. More argument and function customization details are in the Help or Documentation page of the package.
cityview(name = c("Vienna"), zoom = 1, legend = TRUE, places = 40,
license = TRUE, timeout = 120, verbose = TRUE, bot = FALSE)
Note: Timeout value may need to be high for big cities. Otherwise a runtime error may occur.
After rendering the image, Export option in Plots will transform the map into PNG or PDF file. The resolution of the image can be customized on that screen.
Map of Vienna (10000 x 8690 px)
Click here to see as full resolution.
Map of Milan (7560 x 6570 px)
Click here to see as full resolution.
Lastly, there are many useful packages for RStudio and it is an open source data analysis software.
I’d like to thank Professor Derks for his contributions for that artistic package.