1. Learn
  2. /
  3. Courses
  4. /
  5. Interactive Maps with leaflet in R

Exercise

A Map with a View I

You may have noticed that, by default, maps are zoomed out to the farthest level. Rather than manually zooming and panning, we can load the map centered on a particular point using the setView() function.

leaflet()  %>% 
    addProviderTiles("CartoDB")  %>% 
    setView(lat = 40.7, lng = -74.0, zoom = 10)

Currently, DataCamp has offices at the following locations:

350 5th Ave, Floor 77, New York, NY 10118

Martelarenlaan 38, 3010 Kessel-Lo, Belgium

These addresses were converted to coordinates using the geocode() function in the ggmap package.

  • NYC: (-73.98575, 40.74856)
  • Belgium: (4.717863, 50.881363)

Instructions 1/2

undefined XP
    1
    2

Use the coordinates above to create a map with the "CartoDB" provider tile that is centered on DataCamp's New York office with a zoom of 6.