BaşlayınÜcretsiz başlayın

Creating an Interactive Web Map

Similar to the packages in the tidyverse, the leaflet package makes use of the pipe operator (i.e., %>%) from the magrittr package to chain function calls together. This means we can pipe the result of one function into another without having to store the intermediate output in an object. For example, one way to find every car in the mtcars data set with a mpg >= 25 is to pipe the data through a series of functions.

mtcars  %>% 
    mutate(car = rownames(.))  %>% 
    select(car, mpg)  %>% 
    filter(mpg >= 25)  

To create a web map in R, you will chain together a series of function calls using the %>% operator. Our first function leaflet() will initialize the htmlwidget then we will add a map tile using the addTiles() function.

Bu egzersiz, kursun bir parçasıdır

Interactive Maps with leaflet in R

Kursa Göz Atın

Egzersiz talimatları

  • Load the leaflet library.
  • Call the leaflet() function.
  • Pipe the output of leaflet() into addTiles().
  • Experiment with zooming and panning your first interactive web map.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Load the leaflet library
library(___)

# Create a leaflet map with default map tile using addTiles()
___() %>%
    ___()
Kodu Düzenle ve Çalıştır