library(tidyverse)
library(ggplot2)
library(leaflet)
library(sf)
library(shiny)
library(urbnmapr)
library(viridis)DATA608 Story 7: Energy Production
data <- read.csv("US Energy Data.csv") |>
mutate(
Coal = round(Coal /TotalEnergy * 100, 1),
NaturalGas = round(NaturalGas /TotalEnergy * 100, 1),
Petroleum = round(Petroleum /TotalEnergy * 100, 1),
FossilFuelsTotal = round(FossilFuelsTotal /TotalEnergy * 100, 1),
Nuclear = round(Nuclear /TotalEnergy * 100, 1),
Renewable = round(Renewable /TotalEnergy * 100, 1),
NetInterstateFlow = round(NetInterstateFlow /TotalEnergy * 100, 1),
NetImportsMexicoCanada = round(NetImportsMexicoCanada /TotalEnergy * 100, 1),
Dependency = NetInterstateFlow + NetImportsMexicoCanada
)
states_sf <- get_urbn_map("states", sf = TRUE) |>
st_transform("NAD83")states_sf_coef <- left_join(states_sf, data, by = join_by(state_name == State))
ui <- fluidPage(leafletOutput("map", height = "100vh"))
server <- function(input, output, session) {
pal <- leaflet::colorBin(viridis_pal(option = "C")(2),
domain = states_sf_coef$Dependency,
bins = seq(-50,30,10))
output$map <- renderLeaflet({
leaflet(states_sf_coef) |>
addPolygons(
fillColor = ~pal(states_sf_coef$Dependency),
stroke = FALSE,
fillOpacity = 1,
popup = paste("State: ", states_sf_coef$state_name, "<br>",
"Total Energy Use: ", states_sf_coef$TotalEnergy,
"btu <br>",
"Coal: ", states_sf_coef$Coal, "% <br>",
"Natural Gas: ", states_sf_coef$NaturalGas, "% <br>",
"Petroleum: ", states_sf_coef$Petroleum, "% <br>",
"Nuclear: ", states_sf_coef$Nuclear, "% <br>",
"Renewable: ", states_sf_coef$Renewable, "% <br>",
"Net Interstate Flow: ", states_sf_coef$NetInterstateFlow,
"% <br>",
"Net Imports Mexico/Canada: ",
states_sf_coef$NetImportsMexicoCanada, "% <br>")) |>
addPolylines(color = "black", weight = 1) |>
addLegend(position = "bottomleft",
pal = pal,
values = states_sf_coef$Dependency,
title = "Percent Energy Imported",
opacity = 1) |>
addControl("US Energy Dependency by State in 2023", position = "topleft")
})
}
shinyApp(ui = ui, server = server)Based on the graph we can very clearly see that there are states that overproduce energy and then some of the states around them are taking some of that energy to make up for a deficit that they have. You can see this with Colorado, which has by far the most energy being sent out to other states, there are some other states around it that are taking up quite a bit of it. There are quite a few states that get more than 10 percent of their energy from out of state. Very few actually get anything from outside of the country, the largest importer is Vermont at 31.9% of the states energy coming from Canada. The rest of the states only import 2% or less from out of the country. A negligible amount.
Based on this information we very clearly have quite a bit of interstate energy flow and very little energy being imported from outside the country. In general, I would say that this shows that the US is pretty secure in it’s energy security. The only state really at risk without energy imports from out of the country would be Vermont. Otherwise, the risk lies in the interstate energy grids. There are 3 major grids within the US, the Eastern, Western and Texas grids, having these grids make the national have pretty resilient security. Aside from Texas which has had issues in the recent past when the grid goes down they cannot always get the energy they need to the people who need it. I would think that policy wise the US is in a good state to maintain what is currently in place with perhaps a larger percentage reliance on renewables and nuclear for the Earth’s health.