Code
library(tidyverse)
library(here)
library(sf)
library(terra)
library(tidyterra)
library(gstat)
library(stars)
library(janitor)
library(tmap)
library(spatstat)
February 10, 2024
In this report, I explore oil spill incidents throughout all 58 California counties in the year 2008. I used data from CA Department of Fish and Wildlife (CDFW) Oil Spill Incident Tracking [ds394] that was published on July 29, 2009. “The Office of Spill Prevention and Response (OSPR) Incident Tracking Database is a statewide oil spill tracking information system. The data are collected by OSPR Field Response Team members for Marine oil spills and by OSPR Inland Pollution Coordinators and Wardens for Inland incidents. An ‘incident’, for purposes of this database, is a discharge or threatened discharge of petroleum or other deleterious material into the waters of the state.” The purpose of this analysis is to develop a better understanding of which California counties have the most oil spill incidents and to spatially visualize the oil spill incidents.
Create an interactive map displaying all oil spill incidents in each CA county:
Load all Libraries needed for this analysis.
Load the California county data shape files and the oil spill data sets.
Convert the oil spill data set into a shape file and ensure it has the same coordinate reference system (CRS) as the California counties shape file.
Perform a spatial join of CA counties over oil spill points.
Make an interactive map of oil spill incidents by county.
Determine the number of oil spill incidents in each county to display the counties with the greatest amount of oil spill occurrences:
Group the oil spill data by county and summarize the number of oil spills in each county.
Create the chloropleth map.
Perform a point pattern analysis to assess whether oil spills tend to be more clustered or more uniform than complete spatial randomness:
Convert oil observations to spatial point pattern
Convert county boundaries to observation window
Combine as a point pattern object (points + window)
Plot it
### Convert oil observations to spatial point pattern
oil_ppp <- as.ppp(oil_sf)
### Convert county boundary to observation window
ca_counties_win <- as.owin(ca_counties_sf)
### Combine as a point pattern object (points + window):
oil_full <- ppp(oil_ppp$x, oil_ppp$y, window = ca_counties_win)
plot(oil_full, main = "Oil Spill Incidents from 2008")
Plot the G function to determine clustering:
### Make a sequence of distances over which you'll calculate G(r)
r_vec <- seq(0, 10000, by = 100)
gfunction_out <- envelope(oil_full, fun = Gest, r = r_vec,
nsim = 100, verbose = FALSE)
### Calculate the actual and theoretical G(r) values, using 100
### simulations of CSR for the "theoretical" outcome
gfunction_out ### Check the output of gfunction, then...
Pointwise critical envelopes for G(r)
and observed value for 'oil_full'
Edge correction: "km"
Obtained from 100 simulations of CSR
Alternative: two.sided
Significance level of pointwise Monte Carlo test: 2/101 = 0.0198
.....................................................................
Math.label Description
r r distance argument r
obs hat(G)[obs](r) observed value of G(r) for data pattern
theo G[theo](r) theoretical value of G(r) for CSR
lo hat(G)[lo](r) lower pointwise envelope of G(r) from simulations
hi hat(G)[hi](r) upper pointwise envelope of G(r) from simulations
.....................................................................
Default plot formula: .~r
where "." stands for 'obs', 'theo', 'hi', 'lo'
Columns 'lo' and 'hi' will be plotted as shading (by default)
Recommended range of argument r: [0, 6100]
Available range of argument r: [0, 10000]
### Gather this to plot series in ggplot:
gfunction_long <- gfunction_out %>%
as.data.frame() %>%
pivot_longer(cols = obs:hi, names_to = "model", values_to = "g_val")
### Then make a graph in ggplot:
ggplot(data = gfunction_long, aes(x = r, y = g_val, group = model)) +
geom_line(aes(color = model)) +
theme_minimal() +
labs(x = 'radius (m)', y = 'G(r)')
Oil Spill Incident Tracking [ds394]. California Department of Fish and Wildlife. Published July 29, 2009. Retrieved from: https://gis.data.ca.gov/datasets/CDFW::oil-spill-incident-tracking-ds394-1/about
@online{calbert2024,
author = {Calbert, Madison},
title = {Spatial {Data} {Analysis}},
date = {2024-02-10},
url = {https://madicalbert.github.io/posts/2024-02-10-spatial-data/},
langid = {en}
}