INTRODUCTION

Dataset: EIA Energy Information on Renewable Energy Consumption by Source, January 2013 to August 2017.

Units of raw data are quadrillion BTU.

SET-UP

Load required libraries.

library(knitr)
## Warning: package 'knitr' was built under R version 3.5.3
library(tibble)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3

RAW DATA

Load dataset2 file into R Studio, name the columns, and scan the first two rows to combine the two row header into one column name.

dataset2 <- read.csv("https://raw.githubusercontent.com/Zchen116/assignment-2/master/renew%20energy2.csv", skip = 1, header = FALSE)
names(dataset2)[1] <- "Sector_and_Source"
names(dataset2)[2] <- "1989"
names(dataset2)[3] <- "1990"
names(dataset2)[4] <- "1991"
names(dataset2)[5] <- "1992"
names(dataset2)[6] <- "1993"
names(dataset2)[7] <- "1994"
names(dataset2)[8] <- "1995"
names(dataset2)[9] <- "1996"
names(dataset2)[10] <- "1997"
names(dataset2)[11] <- "1998"
names(dataset2)[12] <- "1999"
names(dataset2)[13] <- "2000"
names(dataset2)[14] <- "2001"
names(dataset2)[15] <- "2002"
names(dataset2)[16] <- "2003"
names(dataset2)[17] <- "2004"
names(dataset2)[18] <- "2005"
names(dataset2)[19] <- "2006"
names(dataset2)[20] <- "2007"
names(dataset2)[21] <- "2008"
head(dataset2)
##             Sector_and_Source  1989  1990  1991  1992  1993  1994  1995
## 1                       Total 6.391 6.206 6.238 5.992 6.261 6.153 6.703
## 2                     Biomass 3.159 2.735 2.782 2.932 2.908 3.028 3.101
## 3                   Biofuels1 0.125 0.111 0.128 0.145 0.169 0.188   0.2
## 4                      Waste2 0.354 0.408  0.44 0.473 0.479 0.515 0.531
## 5     Wood and Derived Fuels3  2.68 2.216 2.214 2.313  2.26 2.324  2.37
## 6                  Geothermal 0.317 0.336 0.346 0.349 0.364 0.338 0.294
##    1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007
## 1 7.166 7.175 6.654 6.677  6.26 5.311 5.888 6.141 6.247 6.407 6.825 6.719
## 2 3.157 3.105 2.928 2.963 3.008 2.622 2.701 2.807  3.01 3.117 3.277 3.503
## 3 0.143 0.184 0.201 0.209 0.236 0.253 0.303 0.404   0.5 0.577 0.771 0.991
## 4 0.577 0.551 0.542  0.54 0.511 0.364 0.402 0.401 0.389 0.403 0.397 0.413
## 5 2.437 2.371 2.184 2.214 2.262 2.006 1.995 2.002 2.121 2.136 2.109 2.098
## 6 0.316 0.325 0.328 0.331 0.317 0.311 0.328 0.331 0.341 0.343 0.343 0.349
##    2008
## 1 7.367
## 2 3.852
## 3 1.372
## 4 0.436
## 5 2.044
## 6  0.36
header_rows <- read.csv("https://raw.githubusercontent.com/Zchen116/assignment-2/master/renew%20energy2.csv", nrows=2, header=FALSE)
new_header <- sapply(header_rows, paste, collapse="_")
names(dataset2) <- new_header
dataset2[-2:-10,1:3]
##      Sector and Source_Total 1989_6.391 1990_6.206
## 1                         Total      6.391      6.206
## 11                      Biomass       0.92       0.58
## 12       Wood and Derived Fuels       0.92       0.58
## 13                   Geothermal      0.005      0.006
## 14            Solar Thermal/PV4      0.053      0.056
## 15                   Commercial      0.102      0.098
## 16                      Biomass      0.099      0.094
## 17                    Biofuels5      0.001          *
## 18                       Waste2      0.022      0.028
## 19      Wood and Derived Fuels3      0.076      0.066
## 20                   Geothermal      0.003      0.003
## 21   Hydroelectric Conventional      0.001      0.001
## 22             Solar Thermal/PV          -          -
## 23                   Industrial      1.871      1.717
## 24                      Biomass      1.841      1.684
## 25                    Biofuels6      0.057       0.05
## 26                       Waste2        0.2      0.192
## 27      Wood and Derived Fuels3      1.584      1.442
## 28                   Geothermal      0.002      0.002
## 29   Hydroelectric Conventional      0.028      0.031
## 30             Solar Thermal/PV          -          -
## 31                         Wind          -          -
## 32               Transportation      0.068       0.06
## 33                      Biomass      0.068       0.06
## 34                    Biofuels7      0.068       0.06
## 35              Electric Power8      3.372      3.689
## 36           Electric Utilities      2.983      3.151
## 37                      Biomass       0.02      0.022
## 38                       Waste2       0.01      0.013
## 39      Wood and Derived Fuels3       0.01      0.008
## 40                   Geothermal      0.197      0.181
## 41   Hydroelectric Conventional      2.765      2.948
## 42             Solar Thermal/PV          *          *
## 43                         Wind          *          *
## 44  Independent Power Producers      0.389      0.538
## 45                      Biomass      0.211      0.295
## 46                       Waste2      0.122      0.175
## 47      Wood and Derived Fuels3      0.089       0.12
## 48                   Geothermal      0.111      0.145
## 49   Hydroelectric Conventional      0.043      0.066
## 50             Solar Thermal/PV      0.003      0.004
## 51                         Wind      0.022      0.029

SUBSET DATA

Create a datasubset with only the Residential Consumption of Renewable Energy rows 11 through 14 from 1989 to 2008.

Replace the first row of the new table with the first row of the raw table to retain the months designation.

dataset2[,1]
##  [1] Total                          Biomass                   
##  [3]     Biofuels1                    Waste2                  
##  [5]     Wood and Derived Fuels3    Geothermal                
##  [7]   Hydroelectric Conventional   Solar Thermal/PV4         
##  [9]   Wind                       Residential                 
## [11]   Biomass                        Wood and Derived Fuels  
## [13]   Geothermal                   Solar Thermal/PV4         
## [15] Commercial                     Biomass                   
## [17]     Biofuels5                    Waste2                  
## [19]     Wood and Derived Fuels3    Geothermal                
## [21]   Hydroelectric Conventional   Solar Thermal/PV          
## [23] Industrial                     Biomass                   
## [25]     Biofuels6                    Waste2                  
## [27]     Wood and Derived Fuels3    Geothermal                
## [29]   Hydroelectric Conventional   Solar Thermal/PV          
## [31]   Wind                       Transportation              
## [33]   Biomass                        Biofuels7               
## [35] Electric Power8              Electric Utilities          
## [37]   Biomass                        Waste2                  
## [39]     Wood and Derived Fuels3    Geothermal                
## [41]   Hydroelectric Conventional   Solar Thermal/PV          
## [43]   Wind                       Independent Power Producers 
## [45]   Biomass                        Waste2                  
## [47]     Wood and Derived Fuels3    Geothermal                
## [49]   Hydroelectric Conventional   Solar Thermal/PV          
## [51]   Wind                      
## 21 Levels:     Biofuels1     Biofuels5     Biofuels6 ... Transportation
renewable_res <- dataset2[11:14,]
head(renewable_res)
##    Sector and Source_Total 1989_6.391 1990_6.206 1991_6.238 1992_5.992
## 11                    Biomass       0.92       0.58       0.61       0.64
## 12     Wood and Derived Fuels       0.92       0.58       0.61       0.64
## 13                 Geothermal      0.005      0.006      0.006      0.006
## 14          Solar Thermal/PV4      0.053      0.056      0.058       0.06
##    1993_6.261 1994_6.153 1995_6.703 1996_7.166 1997_7.175 1998_6.654
## 11       0.55       0.52       0.52       0.54       0.43       0.38
## 12       0.55       0.52       0.52       0.54       0.43       0.38
## 13      0.007      0.006      0.007      0.007      0.008      0.008
## 14      0.062      0.064      0.065      0.065      0.065      0.065
##    1999_6.677 2000_6.26 2001_5.311 2002_5.888 2003_6.141 2004_6.247
## 11       0.39      0.42       0.37       0.38        0.4       0.41
## 12       0.39      0.42       0.37       0.38        0.4       0.41
## 13      0.009     0.009      0.009       0.01      0.013      0.014
## 14      0.064     0.061       0.06      0.059      0.058      0.059
##    2005_6.407 2006_6.825 2007_6.719 2008_7.367
## 11       0.43       0.39       0.43       0.45
## 12       0.43       0.39       0.43       0.45
## 13      0.016      0.018      0.022      0.026
## 14      0.061      0.067      0.075      0.088

Build vectors from the raw data so it will be easier to manipulate

Convert the units because Quadrillion BTU (“Quads”) is not commonly used, instead use Giga-Watthours (“GWh”)

Conversion factor: 1 Quad = 293,071.07 GWh

Round the numbers for ease of viewing

Time <- c(new_header)
Geothermal <- round(mapply(`*`, as.numeric(c(renewable_res[1,])), 293071.07), digits = 1)
Solar <- round(mapply(`*`, as.numeric(c(renewable_res[2,])), 293071.07), digits = 1)
Biomass <- round(mapply(`*`, as.numeric(c(renewable_res[3,])) , 293071.07), digits = 1)
Total <- round(mapply(`*`, as.numeric(c(renewable_res[4,])), 293071.07), digits = 1)

Create a dataframe from the original data making the rows vectors

new_data <- data.frame(Time, Geothermal, Solar, Biomass, Total)
head(new_data)
##                          Time Geothermal   Solar Biomass   Total
## V1 Sector and Source_Total    2344569 1758426 2637640 3516853
## V2                 1989_6.391    8499061 8499061 1758426 3516853
## V3                 1990_6.206    8792132 8792132 2051498 4396066
## V4                 1991_6.238    9378274 9378274 2051498 4396066
## V5                 1992_5.992    8792132 8792132 2051498 4102995
## V6                 1993_6.261    9085203 9085203 2051498 4102995

Remove the first row because this is not valid information as part of the datasubset

new_data <- new_data[-1,]
head(new_data)
##          Time Geothermal   Solar Biomass   Total
## V2 1989_6.391    8499061 8499061 1758426 3516853
## V3 1990_6.206    8792132 8792132 2051498 4396066
## V4 1991_6.238    9378274 9378274 2051498 4396066
## V5 1992_5.992    8792132 8792132 2051498 4102995
## V6 1993_6.261    9085203 9085203 2051498 4102995
## V7 1994_6.153    8792132 8792132 2051498 4102995

Analysis

Plot the data to visualize the change in renewable energy consumption in the residential sector and to determine if one technology is contributing more than others to thte overall trends.

Plot the total renewable energy consumed in the residential sector using blue.

ggplot(data=new_data, aes(x=Time, y=Total, group=1)) +
  geom_line(color="#0066ff", size=1) +
  geom_point(color="#0066ff", size=2) +
  scale_x_discrete(breaks=c("2013","2014","2015","2016","2017","2018")) +
  ggtitle("Monthly Consumption of Total Renewable Energy in GWh for Residential Sector") +
  labs(x="January 2013 to August 2018", y="Consumption in GWh") +
  theme(axis.title.y = element_text(size=12, color="#666666")) +
  theme(axis.text = element_text(size=12, family="Trebuchet MS")) +
  theme(plot.title = element_text(size=12, family="Trebuchet MS", face="bold", hjust=0, color="#666666"))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

Plot the solar component of the renewable energy consumed in the residential sector using red.

ggplot(data=new_data, aes(x=Time, y=Solar, group=1)) +
  geom_line(color="#aa0022", size=1) +
  geom_point(color="#aa0022", size=2) +
  scale_x_discrete(breaks=c("2013","2014","2015","2016","2017","2018")) +
  ggtitle("Monthly Consumption of Solar Energy in GWh for Residential Sector") +
  labs(x="January 2013 to August 2018", y="Consumption in GWh") +
  theme(axis.title.y = element_text(size=12, color="#666666")) +
  theme(axis.text = element_text(size=12, family="Trebuchet MS")) +
  theme(plot.title = element_text(size=12, family="Trebuchet MS", face="bold", hjust=0, color="#666666"))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

Conclusion

These two graphs show that monthly renewable energy consumed by the residential sector has been volatile up and down from January 2013 to August 2018. However, the monthly consumption of solar has been a little bit down on the second graph.