Get startedGet started for free

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)

This exercise is part of the course

Interactive Maps with leaflet in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Map with CartoDB tile centered on DataCamp's NYC office with zoom of 6
leaflet()  %>% 
    addProviderTiles("___")  %>% 
    setView(lng = -73.___, lat = 40.___, zoom = ___)
Edit and Run Code