ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Interactive Maps with leaflet in R

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Load the leaflet library
library(___)

# Create a leaflet map with default map tile using addTiles()
___() %>%
    ___()
Editar y ejecutar código