帶有預設視角的地圖 I
你可能已經注意到,地圖在預設情況下會縮到最遠的層級。與其手動縮放與拖曳平移,你可以使用 setView() 函式,直接載入以特定點為中心的地圖。
leaflet() %>%
addProviderTiles("CartoDB") %>%
setView(lat = 40.7, lng = -74.0, zoom = 10)
目前,DataCamp 在以下地點設有辦公室:
350 5th Ave, Floor 77, New York, NY 10118
Martelarenlaan 38, 3010 Kessel-Lo, Belgium
這些地址是用 ggmap 套件中的 geocode() 函式轉換成座標的。
- 紐約(NYC):(-73.98575, 40.74856)
- 比利時(Belgium):(4.717863, 50.881363)
本練習屬於課程
在 R 中使用 leaflet 製作互動式地圖
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Map with CartoDB tile centered on DataCamp's NYC office with zoom of 6
leaflet() %>%
addProviderTiles("___") %>%
setView(lng = -73.___, lat = 40.___, zoom = ___)