Getting Started - Create a map widget - lealflet()


Now that the leaflet R package is installed and loaded into the R Console, let us create a map widget using leaflet() function and add a base map tile using addTiles() to it as follows:

m = leaflet() # creates map widget with just the zoom controls
m

m = addTiles(m) # adds the default OSM (Open Street Map) base map tile on widget
m # print the map

We get a flat tiled World map with Open Street Map (OSM) default base map tile. By default, we can pan and zoom the map.

The same code could be written using the pipe operator %>% from magrittr R package. Pipe operator is not mandatory to use though.

m = leaflet() %>%
  addTiles()
m # print the map