OpenStreetMap logo 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 <- 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: Screen Shot 2021-01-18 at 11 07 50 PM

Happy mapping & coding!

Location: Gokula, Mathikere, Bengaluru North City Corporation, Bengaluru, Bangalore North, Bengaluru Urban, Karnataka, 560013, India
Email icon Bluesky Icon Facebook Icon LinkedIn Icon Mastodon Icon Telegram Icon X Icon

Discussion

Log in to leave a comment