knitr::opts_chunk$set(
  fig.width=8, 
  fig.height=5,
  collapse = TRUE,
  warning = FALSE, 
  message = FALSE,
  comment = "#>"
)

The USgrid R package provides a set of high frequency (hourly) time-series datasets, describing the demand and generation of electricity in the US (lower-48 states, excluding Alaska and Hawaii). That includes the following series:

Data structure

All the series are in tsibble format

The US total demand and supply for electricity

The US_elec series describes the total hourly demand and supply (generation) of electricity in the US since July 2015:

library(USgrid)

data("US_elec")

head(US_elec)

Where the type variable defines the series key (i.e., demand or generation). As you can see in the plot below, the generation of electricity is relatively close to the demand:

library(plotly)

plot_ly(data = US_elec,
        x = ~ date_time,
        y = ~ series,
        color = ~ type,
        line = list(width = 1),
        type = "scatter",
        mode = "lines") %>%
  layout(title = "US Electricity Generation vs. Demand",
         yaxis = list(title = "Mwh"),
         xaxis = list(title = "Source: US Energy Information Administration (Mar 2021)"))

Generation by energy source

The US_source series describes the net generation of electricity by energy source (i.e., natural gas, coal, solar, etc.) since July 2018:

library(tidyr)

data("US_source")

source_wider <- US_source %>% 
  pivot_wider(names_from = source, values_from = series)

 plot_ly(data = source_wider, x = ~date_time, y = ~`natural gas`, 
             name = "Natural Gas", 
             type = "scatter", 
             mode = "none", 
             stackgroup = "one", 
             groupnorm = "percent",
             fillcolor = "lightgreen") %>%
  add_trace(y = ~coal, name = "Coal", fillcolor = "#7f7f7f") %>%
  add_trace(y = ~nuclear, name = "Nuclear", fillcolor = "#F5FF8D") %>%
  add_trace(y = ~hydro, name = "Hydro", fillcolor = "red") %>%
  add_trace(y = ~wind, name = "Wind", fillcolor = "#1f77b4") %>%
  add_trace(y = ~other, name = "Other", fillcolor = "#e377c2") %>%
  add_trace(y = ~solar, name = "Solar", fillcolor = "orange") %>%
  add_trace(y = ~petroleum, name = "Petroleum", fillcolor = "black") %>%
  layout(title = "US Electricity Generation by Energy Source Dist.",
         xaxis = list(title = "Source: US Energy Information Administration (Mar 2021)",
                      showgrid = FALSE),
         yaxis = list(title = "Percentage",
                      showgrid = FALSE,
                      ticksuffix = "%"))

California subregion - demand by operator

The Cal_elec series provides hourly demand by operator since July 2018 for California subregion. That includes the following operators:

data("Cal_elec")

plot_ly(data = Cal_elec,
        x = ~ date_time,
        y = ~ series,
        color = ~ operator,
        type = "scatter",
        mode = "lines") %>%
  layout(title = "California Hourly Demand by Operator",
         yaxis = list(title = "Mwh"),
         xaxis = list(title = "Source: US Energy Information Administration (Mar 2021)"))


RamiKrispin/USgrid documentation built on March 26, 2021, 11:56 p.m.