Chapter 5 Mapping Vector Data

5.1 Map point vector data of superfund sites

Alrighty! Now our data seems to be prepared and we can move on to mapping our data.

First things first, this website will be extremely useful in producing leaflet maps : https://rstudio.github.io/leaflet/.

Let's map the superfund sites.
Start by calling leaflet()- this tells R that we want to create an interactive map using the leaflet package. Next, we want to add a basemap (a background). To do this, we tell R addTiles(). Note: the %>% symbols tell R to add another layer to the map.
Now, we have an interactive map interface and a background map. Naturally, the next step is actually adding our data to the top of the map. Before we add our data to the map we have to consider: What type of data is our superfund dataset? In this case, it's point vector data, where each point represents the location of a superfund site. We use the function addMarkers() to add point data to the leaflet map.

leaflet() %>% 
  addTiles() %>% 
  addMarkers(data = superfund_projected)

What if we want to add other data types other than point vector data? We just need to change the function name that calls the data.

  • addMarkers() adds point vector data
  • addPolylines() adds line data
  • addPolygons() adds polygon data
  • addRasterImage() adds raster data to a map.

5.2 Map polygon vector data of the social vulnerability index

Now, let's try a more complex example. Let's try to map the social vulnerability index data. First, let's start by initializing our leaflet map and adding a basemap to it: leaflet() %>% addTiles(). Next, we add our social vulnerability data as a layer to the map. Again, let's reflect what type of data the social vulnerability index is... So, the social vulnerability index is an aggregated dataset. Each census track gets a value from 0 (no vulnerability) to 1 (high vulnerability) representing the social vulnerability of that census track area. So now we know that this dataset is areal- this means that it cannot be a point or line type of data and it can only be represented by polygons. Therefore, we use addPolygons() to add our SVI dataset.

leaflet() %>% addTiles() %>% 
  addPolygons(data = svi_projected)