Get startedGet started for free

Making our Map Pop

Similar to building a plot with ggplot2 or manipulating data with dplyr, your map needs to be stored in an object if you reference it later in your code.

Speaking of dplyr, the %>% operator can pipe data into the function chain that creates a leaflet map.

ipeds %>% 
    leaflet()  %>% 
        addTiles() %>% 
        addCircleMarkers(popup = ~name, color = "#FF0000")


Piping makes our code more readable and allows us to refer to variables using the ~ operator rather than repeatedly specifying the data frame.

The color argument in addCircleMarkers() takes the name of a color or a hex code. For example, red or #FF0000.

map has been printed for you. Notice the circle markers are gone!

This exercise is part of the course

Interactive Maps with leaflet in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Add circle markers with popups for college names
map %>% 
    addCircleMarkers(data = ca, radius = 2, popup = ___)
Edit and Run Code