@@ -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+
3045Data source: The US Energy Information Administration [ API] ( https://www.eia.gov/ )
3146
3247More 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