Exercise

Adding Popups and Storing your Map

To make our map more informative we can add popups. To add popups that appear when a marker is clicked we need to specify the popup argument in the addMarkers() function. Once we have a map we would like to preserve, we can store it in an object. Then we can pipe this object into functions to add or edit the map's layers.

dc_nyc <- 
    leaflet() %>% 
        addTiles() %>% 
        addMarkers(lng = -73.98575, lat = 40.74856, 
                   popup = "DataCamp - NYC") 

dc_nyc %>% 
    setView(lng = -73.98575, lat = 40.74856, 
            zoom = 2)

Let's try adding popups to both DataCamp location markers and storing our map in an object.

Instructions

100 XP
  • Add the popup argument to addMarkers() to display the value in the hq column and store the leaflet map in an object called map.
  • Center the view of map on the Belgium HQ with a zoom of 5 and store it in map_zoom.
  • Print the map_zoom object.