OpenStreetMap

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 <- c(left=77.17, bottom=12.59, right=78.05, top=13.34)

Finally run below code to generate map tiles:
get_stamenmap(bengaluruCoords, maptype = "terrain") %>% ggmap()

Here is the output: Screen Shot 2021-01-18 at 11 07 50 PM

Happy mapping & coding!

Location: Sundar Nagar, Gokula, Bengaluru, Bangalore North, Bengaluru Urban, Karnataka, 560001, India

Discussion

Log in to leave a comment