Plot simple map using R
Posted by Chetan_Gowda on 19 January 2021 in English. Last updated on 21 January 2021.You can plot simple Stamen map (© OpenStreetMap contributors) in R using below steps:
Install below packages in R Studio:
install.packages("sf")
install.packages("ggplot2")
install.packages("ggmap")
Once you installed, do load them using below code:
library(sf)
library(ggmap)
Next go to Geofabrik Tile calculator and copy the desired location co-ordinates.
Example: I copied Bengaluru co-ordinates using Coordinate Display tab under Osmosis copy and stored in bengaluruCoords like below:
bengaluruCoords <- https://wiki.openstreetmap.org/wiki/Tag:c(left=77.17, https://wiki.openstreetmap.org/wiki/Tag:bottom=12.59, https://wiki.openstreetmap.org/wiki/Tag:right=78.05, https://wiki.openstreetmap.org/wiki/Tag:top=13.34)
Finally run below code to generate map tiles:
get_stamenmap(bengaluruCoords, maptype = "terrain") %>% ggmap()
Here is the output:

Happy mapping & coding!
Discussion