Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Interactive Maps with leaflet in R

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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 %>% 
    ___() 
Code bewerken en uitvoeren