Spatial data visualization (interactive map & choropleth)
Overview
In this report, I make an exploratory interactive map in tmap showing
the location of oil spill events in California. The final graph results
are displayed via a choropleth map in ggplot in which the fill color for
each county depends on the count of inland oil spill events using the
variable InlandMari
by county for the 2008 oil spill
data.
Data source: 1.Oil Spill Incident Tracking [ds394] GIS Dataset. https://map.dfg.ca.gov/metadata/ds0394.html.
2.CA Geographic Boundaries - California Open Data. https://data.ca.gov/dataset/ca-geographic-boundaries.
Data Wrangling
<- read_sf(here("data", "CA_Counties", "CA_Counties_TIGER2016.shp"))
ca_counties_sf <- ca_counties_sf %>%
ca_subset_sf ::clean_names() %>%
janitorselect(county_name = name, land_area = aland)
# head(ca_subset_sf)
# Check the CRS:
%>% st_crs()
ca_subset_sf %>% raster::crs() ### to show proj4 string
ca_subset_sf
# ggplot(data = ca_subset_sf) +
# geom_sf(aes(fill = land_area), color = "white", size = 0.1) +
# theme_void() +
# scale_fill_gradientn(colors = c("cyan","blue","purple"))
Data Analysis
Here we look at the data from the 2008 Oil Spill Incident Tracking in California using GIS Dataset.
<- read_sf(here("data","Oil_Spill_Incident_Tracking_[ds394]")) %>%
oil_spill_sf ::clean_names()
janitor
# Check the CRS:
%>% st_crs()
oil_spill_sf %>% raster::crs() oil_spill_sf
Data Exploration & Vizualization
- Initial plot of the 2008 oil spill events in California
# Set the viewing mode to "interactive":
tmap_mode(mode = "view")
# Then make a map (with the polygon fill color updated by variable 'land_area', updating the color palette to BuPu), then add another shape layer for the oil spill records (added as dots):
tm_shape(ca_subset_sf) +
tm_fill("land_area", palette = "BuPu") +
tm_shape(oil_spill_sf) +
tm_markers(
shape = marker_icon(),
col = NA,
border.col = NULL,
clustering = TRUE,
text = NULL,
text.just = "top",
markers.on.top.of.text = TRUE,
group = NA
)