Choropleth and interactive maps exploring California oil spills.
This report contains the following exploratory maps of the oil spill events that took place in California during 2008:
choropleth map showing the number of inland oil spill events by county, and
interactive map showing the location of oil spill events included in the data and the number of inland oils spill events by county.
Data comes from the California State Geoportal oil spill incident tracking.
All plots are made using R version 4.0.2 using RStudio Version 1.3.1093.
# ---- READ DATA ----
raw_counties <- read_sf(here("_posts",
"2021-03-12-oil-spill-maps",
"data",
"CA_counties",
"CA_Counties_TIGER2016.shp")) %>%
clean_names()
raw_spills <- read_sf(here(
"_posts",
"2021-03-12-oil-spill-maps",
"data","Oil_Spill_Tracking",
"Oil_Spill_Incident_Tracking_%5Bds394%5D.shp")) %>%
clean_names()
# --- CHECK COORDINATE REFERENCE SYSTEMS (CRS)
# in this case both use WGS 84 / Pseudo-Mercator
#raw_counties %>% st_crs()
#raw_spills %>% st_crs()
# ---- DATA SELECTION ----
ca_counties <- raw_counties %>%
select(name) %>%
rename(county_name = name)
# select subset of spill information
oil_spills <- raw_spills %>%
rename(city=localecity,
county=localecoun,
location=inlandmari,
date_of_incident = dateofinci) %>%
select(objectid, date_of_incident, location, waterway, city:longitude)
# ---- CHOROPLETH MAP BY # OF INLAND SPILLS BY COUNTY
# select only inland spills
inland_spills <- oil_spills %>%
filter(location == "Inland") %>%
select(county)
# count of inland spills by county
count_inland_spills <- ca_counties %>%
st_join(inland_spills) %>%
count(county_name)
# create map
ggplot(data = count_inland_spills) +
geom_sf(aes(fill = n), color = "white", size = 0.3) +
theme_bw() + # shows coordinates
scale_fill_gradientn(colors = c("papayawhip","orange","red"))+
labs(title = "Number of inland oil spills in each California county during 2008",
fill = "Number of oil spills")
Figure 1. Map of the number of inland oil spill incidents by California county. The color of each county corresponds to the number of inland oil spills that took place in that county during 2008. Data: CA DFW Oil Spill Incident Tracking
# count of all oil spills by county
spills_by_counties <- ca_counties %>%
st_join(oil_spills) %>%
count(county_name) %>%
rename(total_spills=n)
# create interactive map
tmap_mode(mode = "view")
tm_shape(spills_by_counties) +
tm_basemap("OpenStreetMap.Mapnik")+ # fix base map
tm_borders("white", lwd = 1) +
tm_polygons("total_spills", palette = "Oranges", alpha=0.8) +
tm_shape(oil_spills) +
tm_dots(col="brown4", size=0.03, alpha=0.8)+
labs(title="Oil spill events in California during 2008")