CommencerCommencer gratuitement

Building a Base

Now that we know where to center our map (Lat = 39.8282, Lng = -98.5795), let's build a new basemap. Remember that we can use either addTiles() or addProviderTiles() to add a map tile to our leaflet object.

Since we are working toward mapping all of America's colleges, we can include the ipeds data at the start of the chain of functions that will create our base map. This way the ipeds data will be stored with our base map so that we can easily access it. Once we have built a solid base, we can map every college in America with just two lines of R code.

The ipeds data and leaflet and tidyverse libraries have been loaded for you.

Cet exercice fait partie du cours

Interactive Maps with leaflet in R

Afficher le cours

Instructions

  • Store a new map in the m2 object that:
    • Uses the CartoDB provider tile.
    • Has a zoom level of 3.
    • Then add circle markers to m2 to map all of America's colleges.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

m2 ___ 
    ipeds %>% 
        leaflet() %>% 
            # use the CartoDB provider tile
            addProviderTiles(___) %>% 
            # center on the middle of the US with zoom of 3
            setView(lat = 39.8282, lng = -98.5795, ___)

# Map all American colleges 
m2 %>% 
    ___() 
Modifier et exécuter le code