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.
Diese Übung ist Teil des Kurses
Interactive Maps with leaflet in R
Anleitung zur Übung
- Load the
leaflet
library. - Call the
leaflet()
function. - Pipe the output of
leaflet()
intoaddTiles()
. - Experiment with zooming and panning your first interactive web map.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Load the leaflet library
library(___)
# Create a leaflet map with default map tile using addTiles()
___() %>%
___()