-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
148 lines (109 loc) · 4.83 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
fig.height=5, fig.width=8,
message=FALSE, warning=FALSE,
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%")
```
# USgas <a href='https://ramikrispin.github.io/USgas/'><img src='man/figures/USgas.png' align="right" width="150" height="150" /></a>
<!-- badges: start -->
[](https://cran.r-project.org/package=USgas) [](https://lifecycle.r-lib.org/articles/stages.html) [](https://opensource.org/license/mit/) [](https://github.com/RamiKrispin/USgas/commit/main)
<!-- badges: end -->
The **USgas** package provides an overview of demand for natural gas in the US in a time-series format. That includes the following dataset:
* `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:
- Commercial Consumption
- Delivered to Consumers
- Electric Power Consumption
- Industrial Consumption
- Lease and Plant Fuel Consumption
- Pipeline Fuel Consumption
- Residential Consumption
- Vehicle Fuel Consumption
The package also includes the following datasets, from previous release:
* `us_total` - The US annual natural gas consumption by state-level between 1997 and 2019, and aggregate level between 1949 and 2019
* `us_monthly` - The monthly demand for natural gas in the US between 2001 and 2020
* `us_residential` - The US monthly natural gas residential consumption by state and aggregate level between 1989 and 2020
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.
Data source: The US Energy Information Administration [API](https://www.eia.gov/)
More information about the package datasets available on this [vignette](https://ramikrispin.github.io/USgas/articles/introduction.html).
## Installation
You can install the released version of USgas from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("USgas")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("RamiKrispin/USgas")
```
## Example
Let's load the data:
```{r}
data("usgas")
head(usgas)
str(usgas)
```
Plotting the residential consumption of natural gas in the US:
``` r
library(plotly)
us_res <- usgas[which(usgas$state == "U.S." & usgas$process == "Residential Consumption"), ]
plot_ly(data = us_res,
x = ~ date,
y = ~ y,
type = "scatter",
mode = "line") |>
layout(title = "US Monthly Residential Consumption",
yaxis = list(title = "MMCF"),
xaxis = list(title = "Source: EIA API"))
```
```{r, include = FALSE}
library(plotly)
us_res <- usgas[which(usgas$state == "U.S." & usgas$process == "Residential Consumption"), ]
p1 <- plot_ly(data = us_res,
x = ~ date,
y = ~ y,
type = "scatter",
mode = "line") |>
layout(title = "US Monthly Natural Gas Consumption by Residential Consumers",
yaxis = list(title = "MMCF"),
xaxis = list(title = "Source: EIA API"))
orca(p1, "man/figures/us_res.svg")
```
<img src="man/figures/us_res.svg" width="100%" />
Plotting the total monthly natural gas delivered in the New England states:
```r
ne <- c("Connecticut", "Maine", "Massachusetts",
"New Hampshire", "Rhode Island", "Vermont")
ne_gas <- usgas[which(usgas$state %in% ne & usgas$process == "Delivered to Consumers"),]
plot_ly(data = ne_gas,
x = ~ date,
y = ~ y,
color = ~ state,
type = "scatter",
mode = "line") |>
layout(title = "Total Natrual Gas Delivered to Consumers in New England States",
yaxis = list(title = "MMCF"),
xaxis = list(title = "Source: EIA API"))
```
```{r , include = FALSE}
ne <- c("Connecticut", "Maine", "Massachusetts",
"New Hampshire", "Rhode Island", "Vermont")
ne_gas <- usgas[which(usgas$state %in% ne & usgas$process == "Delivered to Consumers"),]
p2 <- plot_ly(data = ne_gas,
x = ~ date,
y = ~ y,
color = ~ state,
type = "scatter",
mode = "line") |>
layout(title = "Total Natrual Gas Delivered to Consumers in New England States",
yaxis = list(title = "MMCF"),
xaxis = list(title = "Source: EIA API"))
orca(p2, "man/figures/new_england.svg")
```
<img src="man/figures/new_england.svg" width="100%" />