Skip to content

Commit e9971de

Browse files
authored
Merge pull request #1 from RamiKrispin/data-refresh-04/22
Data refresh 04/22
2 parents 190610d + 1706f22 commit e9971de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+122605
-22332
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
^data_raw$
77
^LICENSE\.md$
88
^CRAN-RELEASE$
9+
^CRAN-SUBMISSION$

CRAN-SUBMISSION

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Version: 0.1.2
2+
Date: 2023-04-16 06:30:52 UTC
3+
SHA: efb45230dddbd71b96c33b71c990eb6976f18b7f

DESCRIPTION

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: USgas
22
Type: Package
33
Title: The Demand for Natural Gas in the US
4-
Version: 0.1.1
4+
Version: 0.1.2
55
Authors@R: person(given = "Rami",
66
family ="Krispin",
77
email = "rami.krispin@gmail.com",
@@ -13,10 +13,11 @@ Encoding: UTF-8
1313
LazyData: true
1414
Depends:
1515
R (>= 2.10)
16-
RoxygenNote: 7.1.1
16+
RoxygenNote: 7.2.1
1717
URL: https://github.com/RamiKrispin/USgas
1818
BugReports: https://github.com/RamiKrispin/USgas/issues
1919
Suggests:
2020
knitr,
21-
rmarkdown
21+
rmarkdown,
22+
plotly
2223
VignetteBuilder: knitr

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# USgas 0.1.2
2+
3+
* Add new dataset `usgas`, describing the US monthly natural gas consumption by end-use on the state and US aggregate level
4+
* Deprecating the previous package datasets - `us_residential`, `us_total`, and `us_total`, as they can be generated by the `usgas` dataset
5+
16
# USgas 0.1.1
27

38
* Fixing CRAN errors - removing the `digits` argument from the `format` function

R/usgas.R

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#' US Monthly Consumption of Natural Gas by End Use
2+
#' @description The US monthly consumption of natural gas by end-use and state between 1973 (US aggregate, state level since 1989) and 2022.
3+
#'
4+
#' Units: Million Cubic Feet
5+
#'
6+
#'
7+
#' @format A data.frame with 6 variables.
8+
#' \describe{
9+
#' \item{date}{A Date, the month and year of the observation (the day set by default to 1st of the month)}
10+
#' \item{process}{The process type description}
11+
#' \item{state}{The US state name}
12+
#' \item{state_abb}{the US state abbreviation}
13+
#' \item{y}{A numeric, the monthly natural gas residential consumption in a million cubic feet}
14+
#' }
15+
#' @source US Energy Information Administration (EIA) \href{https://www.eia.gov/}{website}.
16+
#' @keywords datasets timeseries natural gas us state
17+
#' @details The dataset contains monthly summary of the consumption of natural gas
18+
#' by end-use in the US by state and total aggregate level. The data is available
19+
#' for the state level between January 1989 and December 2022, and for the US level
20+
#' between January 1973 and Dec 2022. It includes the following end-use categories:
21+
#'
22+
#' - Commercial Consumption
23+
#' - Delivered to Consumers
24+
#' - Electric Power Consumption
25+
#' - Industrial Consumption
26+
#' - Lease and Plant Fuel Consumption
27+
#' - Pipeline Fuel Consumption
28+
#' - Residential Consumption
29+
#' - Vehicle Fuel Consumption
30+
#'
31+
#' @examples
32+
#'
33+
#' library(plotly)
34+
#'
35+
#' data("usgas")
36+
#'
37+
#' head(usgas)
38+
#'
39+
#' # Plot the US consumption
40+
#'
41+
#' us_df <- usgas[which(usgas$state == "U.S."), ]
42+
#'
43+
#' plot_ly(data = us_df,
44+
#' x = ~ date,
45+
#' y = ~ y,
46+
#' color = ~ process,
47+
#' type = "scatter",
48+
#' mode = "line") |>
49+
#' layout(title = "US Monthly Consumption by End Use",
50+
#' yaxis = list(title = "MMCF"),
51+
#' xaxis = list(title = "Source: EIA Website"),
52+
#' legend = list(x = 0, y = 1.05),
53+
#' margin = list(l = 50, r = 50, b = 70, t = 60))
54+
#'
55+
#'
56+
#' # Plot the California consumption
57+
#'
58+
#' ca_df <- usgas[which(usgas$state == "California"), ]
59+
#'
60+
#' plot_ly(data = ca_df,
61+
#' x = ~ date,
62+
#' y = ~ y,
63+
#' color = ~ process,
64+
#' type = "scatter",
65+
#' mode = "line") |>
66+
#' layout(title = "California Monthly Consumption by End Use",
67+
#' yaxis = list(title = "MMCF"),
68+
#' xaxis = list(title = "Source: EIA Website"),
69+
#' legend = list(x = 0, y = 1.05),
70+
#' margin = list(l = 50, r = 50, b = 70, t = 60))
71+
#'
72+
"usgas"

README.Rmd

+86-90
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,31 @@ knitr::opts_chunk$set(
1717
# USgas <a href='https://ramikrispin.github.io/USgas/'><img src='man/figures/USgas.png' align="right" width="150" height="150" /></a>
1818

1919
<!-- badges: start -->
20-
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/USgas)](https://cran.r-project.org/package=USgas) [![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![GitHub commit](https://img.shields.io/github/last-commit/RamiKrispin/USgas)](https://github.com/RamiKrispin/USgas/commit/main)
20+
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/USgas)](https://cran.r-project.org/package=USgas) [![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit/) [![GitHub commit](https://img.shields.io/github/last-commit/RamiKrispin/USgas)](https://github.com/RamiKrispin/USgas/commit/main)
2121

2222
<!-- badges: end -->
2323

24-
The **USgas** package provides an overview of demand for natural gas in the US in a time-series format. That includes the following datasets:
24+
The **USgas** package provides an overview of demand for natural gas in the US in a time-series format. That includes the following dataset:
25+
26+
* `usgas` - The monthly consumption of natural gas in the US/state level by end-use since 1973 for US level and 1989 for state level. It includes the following end-use categories:
27+
28+
- Commercial Consumption
29+
- Delivered to Consumers
30+
- Electric Power Consumption
31+
- Industrial Consumption
32+
- Lease and Plant Fuel Consumption
33+
- Pipeline Fuel Consumption
34+
- Residential Consumption
35+
- Vehicle Fuel Consumption
36+
37+
The package also includes the following datasets, from previous release:
2538

2639
* `us_total` - The US annual natural gas consumption by state-level between 1997 and 2019, and aggregate level between 1949 and 2019
2740
* `us_monthly` - The monthly demand for natural gas in the US between 2001 and 2020
2841
* `us_residential` - The US monthly natural gas residential consumption by state and aggregate level between 1989 and 2020
2942

43+
The `us_total`, `us_monthly`, and `us_residential` can be derived out of the `usgas` dataset. Therefore, those datasets in the process of deprication and will be removed in the next release to CRAN.
44+
3045
Data source: The US Energy Information Administration [API](https://www.eia.gov/)
3146

3247
More information about the package datasets available on this [vignette](https://ramikrispin.github.io/USgas/articles/introduction.html).
@@ -47,106 +62,87 @@ devtools::install_github("RamiKrispin/USgas")
4762
```
4863
## Example
4964

50-
Plotting the consumption of natural gas in New England states:
65+
Let's load the data:
5166

5267
```{r}
53-
data(us_total)
68+
data("usgas")
5469
55-
str(us_total)
70+
head(usgas)
5671
57-
head(us_total)
72+
str(usgas)
5873
```
5974

6075

61-
Subsetting the New England states:
76+
Plotting the residential consumption of natural gas in the US:
77+
``` r
78+
library(plotly)
79+
80+
us_res <- usgas[which(usgas$state == "U.S." & usgas$process == "Residential Consumption"), ]
81+
82+
plot_ly(data = us_res,
83+
x = ~ date,
84+
y = ~ y,
85+
type = "scatter",
86+
mode = "line") |>
87+
layout(title = "US Monthly Residential Consumption",
88+
yaxis = list(title = "MMCF"),
89+
xaxis = list(title = "Source: EIA API"))
90+
```
6291

63-
```{r}
64-
ne <- c("Connecticut", "Maine", "Massachusetts",
65-
"New Hampshire", "Rhode Island", "Vermont")
66-
ne_gas <- us_total[which(us_total$state %in% ne),]
92+
```{r, include = FALSE}
93+
library(plotly)
94+
95+
us_res <- usgas[which(usgas$state == "U.S." & usgas$process == "Residential Consumption"), ]
96+
97+
p1 <- plot_ly(data = us_res,
98+
x = ~ date,
99+
y = ~ y,
100+
type = "scatter",
101+
mode = "line") |>
102+
layout(title = "US Monthly Natural Gas Consumption by Residential Consumers",
103+
yaxis = list(title = "MMCF"),
104+
xaxis = list(title = "Source: EIA API"))
105+
orca(p1, "man/figures/us_res.svg")
106+
```
67107

68-
ne_wide <- reshape(ne_gas, v.names = "y", idvar = "year",
69-
timevar = "state", direction = "wide")
70-
ne_wide <- ne_wide[order(ne_wide$year), ]
108+
<img src="man/figures/us_res.svg" width="100%" />
71109

72-
names(ne_wide) <- c("year",ne)
73110

74-
head(ne_wide)
75-
```
76111

77-
Plotting the states series:
112+
Plotting the total monthly natural gas delivered in the New England states:
78113

79-
```{r}
80-
# Set the y and x axis ticks
81-
at_x <- seq(from = 2000, to = 2020, by = 5)
82-
83-
at_y <- pretty(ne_gas$y)[c(2, 4, 6)]
84-
85-
# plot the first series
86-
plot(ne_wide$year, ne_wide$Connecticut,
87-
type = "l",
88-
col = "#073b4c",
89-
frame.plot = FALSE,
90-
axes = FALSE,
91-
panel.first = abline(h = c(at_y), col = "grey80"),
92-
main = "New England Annual Natural Gas Consumption by State",
93-
cex.main = 1.2, font.main = 1, col.main = "black",
94-
xlab = "Source: https://www.eia.gov/",
95-
font.axis = 1, cex.lab= 1,
96-
ylab = "Million Cubic Feet",
97-
ylim = c(min(ne_gas$y, na.rm = TRUE), max(ne_gas$y, na.rm = TRUE)),
98-
xlim = c(min(ne_gas$year), max(ne_gas$year) + 3))
99-
100-
# Add the 5 other series
101-
lines(ne_wide$year, ne_wide$Maine, col = "#1f77b4")
102-
lines(ne_wide$year, ne_wide$Massachusetts, col = "#118ab2")
103-
lines(ne_wide$year, ne_wide$`New Hampshire`, col = "#06d6a0")
104-
lines(ne_wide$year, ne_wide$`Rhode Island`, col = "#ffd166")
105-
lines(ne_wide$year, ne_wide$Vermont, col = "#ef476f")
106-
107-
# Add the y and x axis ticks
108-
109-
mtext(side =1, text = format(at_x, nsmall=0), at = at_x,
110-
col = "grey20", line = 1, cex = 0.8)
111-
112-
mtext(side =2, text = format(at_y, scientific = FALSE), at = at_y,
113-
col = "grey20", line = 1, cex = 0.8)
114-
115-
# Add text
116-
text(max(ne_wide$year) + 2,
117-
tail(ne_wide$Connecticut,1),
118-
"Connecticut",
119-
col = "#073b4c",
120-
cex = 0.7)
121-
122-
text(max(ne_wide$year) + 2,
123-
tail(ne_wide$Maine,1) * 0.95,
124-
"Maine",
125-
col = "#1f77b4",
126-
cex = 0.7)
127-
128-
text(max(ne_wide$year) + 2,
129-
tail(ne_wide$Massachusetts,1),
130-
"Massachusetts",
131-
col = "#118ab2",
132-
cex = 0.7)
133-
134-
text(max(ne_wide$year) + 2,
135-
tail(ne_wide$`New Hampshire`,1) * 1.1,
136-
"New Hampshire",
137-
col = "#06d6a0",
138-
cex = 0.7)
139-
140-
text(max(ne_wide$year) + 2,
141-
tail(ne_wide$`Rhode Island`,1) * 1.05,
142-
"Rhode Island",
143-
col = "#ffd166",
144-
cex = 0.7)
145-
146-
text(max(ne_wide$year) + 2,
147-
tail(ne_wide$Vermont,1),
148-
"Vermont",
149-
col = "#ef476f",
150-
cex = 0.7)
114+
```r
115+
ne <- c("Connecticut", "Maine", "Massachusetts",
116+
"New Hampshire", "Rhode Island", "Vermont")
117+
ne_gas <- usgas[which(usgas$state %in% ne & usgas$process == "Delivered to Consumers"),]
118+
119+
plot_ly(data = ne_gas,
120+
x = ~ date,
121+
y = ~ y,
122+
color = ~ state,
123+
type = "scatter",
124+
mode = "line") |>
125+
layout(title = "Total Natrual Gas Delivered to Consumers in New England States",
126+
yaxis = list(title = "MMCF"),
127+
xaxis = list(title = "Source: EIA API"))
128+
```
129+
130+
```{r , include = FALSE}
131+
ne <- c("Connecticut", "Maine", "Massachusetts",
132+
"New Hampshire", "Rhode Island", "Vermont")
133+
ne_gas <- usgas[which(usgas$state %in% ne & usgas$process == "Delivered to Consumers"),]
134+
135+
p2 <- plot_ly(data = ne_gas,
136+
x = ~ date,
137+
y = ~ y,
138+
color = ~ state,
139+
type = "scatter",
140+
mode = "line") |>
141+
layout(title = "Total Natrual Gas Delivered to Consumers in New England States",
142+
yaxis = list(title = "MMCF"),
143+
xaxis = list(title = "Source: EIA API"))
144+
145+
orca(p2, "man/figures/new_england.svg")
151146
```
152147

148+
<img src="man/figures/new_england.svg" width="100%" />

0 commit comments

Comments
 (0)