For this project I chose to research Global Energy Consumption. The purpose of this analysis is to visualize energy consumption by country in order to easily compare and contrast energy usage of multiple countries across a given range of time. Through this analysis I hope to gain insights surrounding traditional fossil fuel consumption and the talks of moving towards renewable resources globally. I am curious to see if we as a planet are making strives towards converting to renewable energy and reducing our use of fossil fuels. I would also like to see which countries are doing more or less than others. Another item I hope to learn is whether we are moving in the ‘right direction’ overall. If my visualizations show that we are using less renewable sources than the past, I would call a step in the ‘wrong direction’. This may also be a rough model that can be used for other purposes as well, such as prediction of future energy consumption levels, both fossil and renewable.
Data was retrieved from: https://www.kaggle.com/pralabhpoudel/world-energy-consumption. Initial data pre-processing was utilized after a first round of exploration. It was noted that many countries had potential missing data before the year of 1965, and that near all countries had missing data for the year 2020, as it had not yet been completed during the initial collection of this data. As such, these years not needed were filtered out accordingly. In addition, NA values were set to zero to allow for better end results, as most all values dealt with are numeric for the purposes of this analysis.
setwd("C:/Users/Sam/Documents/DSCI_605/Final Project/")
library(ggplot2)
library(dplyr)
# Read in and filter years that do not have relevant data
energy <- read.csv('World Energy Consumption.csv', header = TRUE) %>% filter(year >= 1965) %>% filter(year < 2020)
energy$iso_code <- as.factor(energy$iso_code)
energy$country <- as.factor(energy$country)
energy$year <- as.factor(energy$year)
# Set NA to Zero
energy[is.na(energy)] <- 0
Variables of the initial dataset are in total 123. Many of these are not necessary for my simple analysis. Many variables that exist are values such as percent change, gdp, and singular categories of energy consumption such as coal or nuclear. For more concise results, total values were used in this analysis provided by the collector of the data. Categories were predetermined in three denominations. These denominations are Fossil Fuels, Renewables, and Renewables(Other) each measured in terawatt-hours. The following table describes the consistency of the variables.
Resources_Table <- read.csv('Energy Table.csv', header = TRUE)
Resources_Table
## Fossil.Fuels Renewable.Resources Other.Renewables
## 1 Coal Solar Nuclear
## 2 Oil Wind Hydrogen
## 3 Gas Hydro
## 4 Geothermal
# Subset Data into different datasets
renew_energy_con <- subset(energy, select = c("iso_code","country", "year", "population", "renewables_consumption","other_renewable_consumption","hydro_consumption","solar_consumption","wind_consumption"))
fos_energy_con <- subset(energy, select = c("iso_code","country", "year", "population", "fossil_fuel_consumption", "coal_consumption", "gas_consumption", "oil_consumption"))
oth_energy_con <-subset(energy, select = c("iso_code","country", "year", "population", "biofuel_consumption", "nuclear_consumption"))
fos_tot_energy_con <-subset(energy, select = c("iso_code","country", "year", "population", "fossil_fuel_consumption"))
oth_tot_energy_con <-subset(energy, select = c("iso_code","country", "year", "population", "other_renewable_consumption"))
renew_tot_energy_con <-subset(energy, select = c("iso_code","country", "year", "population", "renewables_consumption"))
Data was aggregated by year for data exploration to compare, since data was previously subset to remove unwanted variables. This was mostly done for user organization. Once aggregated, plots were overlayed on each other when possible without skewing results. As such, fossil fuels were awarded their own plot as they are used on a much wider scale than alternative energies.
# Data Exploration Preperation
fos_tot_energy_con_by_year <- aggregate(fos_tot_energy_con['fossil_fuel_consumption'], by=fos_tot_energy_con['year'], sum)
names(fos_tot_energy_con_by_year)[1] <- 'x'
names(fos_tot_energy_con_by_year)[2] <- 'y'
renew_tot_energy_con_by_year <- aggregate(renew_tot_energy_con['renewables_consumption'], by=renew_tot_energy_con['year'], sum)
names(renew_tot_energy_con_by_year)[1] <- 'x'
names(renew_tot_energy_con_by_year)[2] <- 'y'
oth_tot_energy_con_by_year <- aggregate(oth_tot_energy_con['other_renewable_consumption'], by=oth_tot_energy_con['year'], sum)
names(oth_tot_energy_con_by_year)[1] <- 'x'
names(oth_tot_energy_con_by_year)[2] <- 'y'
fos_plot <- ggplot(NULL, aes(x, y)) +
xlab('Years') +
ylab('Terawatt/Hr') +
ggtitle('Fig. 1.1 - Global Energy Consumption By Year') +
geom_point(data = fos_tot_energy_con_by_year, aes(color = "Fossil Fuels")) +
scale_color_manual(values = c("Fossil Fuels" = "brown")) +
scale_x_discrete(breaks = seq(1965, 2020, by = 5))
fos_plot
Figure 1.1 shows irregular behavior around 1984-1985 and 2009-2010. Other than this, it shows a steady increase year by year. This is likely due to rising technology and population causing a near equal rise in demand.
renew_plot <- ggplot(NULL, aes(x, y)) +
xlab('Years') +
ylab('Terawatt/Hr') +
ggtitle('Fig. 1.2 - Global Energy Consumption By Year') +
geom_point(data = renew_tot_energy_con_by_year, aes(color = "Renewable")) +
scale_color_manual(values = c("Renewable" = "green",
"Renewable (Other)" = "blue")) +
geom_point(data = oth_tot_energy_con_by_year, aes(color = "Renewable (Other)")) +
scale_x_discrete(breaks = seq(1965, 2020, by = 5))
renew_plot
Figure 1.2 shows a steady increase year by year, with a sharper ramp up 2003-2004 to current day. It is hard to tell, but similar blips are noticeable during the same years for that of fossil fuels as well, just not with such heavy impact.
library(ggmap)
library(rworldmap)
library(RColorBrewer)
library(tidyverse)
library(dplyr)
mapData <- filter(fos_tot_energy_con, year == "1965")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "1965 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 98 codes from your data successfully matched countries in the map
## 26 codes from your data failed to match with a country code in the map
## 145 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '1965 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.1 - 1965 Fossil Fuel Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(fos_tot_energy_con, year == "1984")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "1984 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 189 codes from your data successfully matched countries in the map
## 33 codes from your data failed to match with a country code in the map
## 54 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '1984 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.2 - 1984 Fossil Fuel Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(fos_tot_energy_con, year == "1985")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "1985 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 191 codes from your data successfully matched countries in the map
## 33 codes from your data failed to match with a country code in the map
## 52 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '1985 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.3 - 1985 Fossil Fuel Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(fos_tot_energy_con, year == "2008")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2008 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 207 codes from your data successfully matched countries in the map
## 34 codes from your data failed to match with a country code in the map
## 36 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '2008 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.4 - 2008 Fossil Fuel Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(fos_tot_energy_con, year == "2009")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2009 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 207 codes from your data successfully matched countries in the map
## 34 codes from your data failed to match with a country code in the map
## 36 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '2009 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.5 - 2009 Fossil Fuel Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(fos_tot_energy_con, year == "2010")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2010 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 207 codes from your data successfully matched countries in the map
## 34 codes from your data failed to match with a country code in the map
## 36 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '2010 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.6 - 2010 Fossil Fuel Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(fos_tot_energy_con, year == "2019")
mapData <- aggregate(mapData$fossil_fuel_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2019 Fossil Fuel Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 203 codes from your data successfully matched countries in the map
## 27 codes from your data failed to match with a country code in the map
## 40 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'OrRd')
mapCountryData(WorldMap,
nameColumnToPlot = '2019 Fossil Fuel Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 2.7 - 2019 Fossil Fuel Energy Consumption - Terawatt/Hr")
Figures 2.1 - 2.7 tell a story of energy usage across the globe. Starting at 1965 (Fig 2.1), the United States is the only country relatively using such fuels at a large scale. Fig 2.2 shows that other countries such as China and parts of Europe are beginning to use more fossil fuels for energy.
From Fig. 2.2 - 2.3 we see an overall drop in energy usage between the years, but also note that Russia began to use these fuels much more prominently. There were a lot of world events occurring during this time which may attribute to such a large drop. India’s prime minister was assassinated during this time period, various acts of terrorism and hijackings occurred, earthquakes and natural disasters, and even other impactful military coups. Fig. 2.4 shows the US and China are the largest users of fossil fuels with other large players in Russia, India, the Middle East, and parts of Europe. Transitioning towards 2010 China begins to take over even that of the United States. This is much more apparent towards our most recent Fig 2.7.
rm(mapData)
mapData <- filter(renew_tot_energy_con, year == "1965")
mapData <- aggregate(mapData$renewables_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "1965 Renewables Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 98 codes from your data successfully matched countries in the map
## 26 codes from your data failed to match with a country code in the map
## 145 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'RdYlGn')
mapCountryData(WorldMap,
nameColumnToPlot = '1965 Renewables Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 3.1 - 1965 Renewables Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(renew_tot_energy_con, year == "1985")
mapData <- aggregate(mapData$renewables_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "1985 Renewables Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 191 codes from your data successfully matched countries in the map
## 33 codes from your data failed to match with a country code in the map
## 52 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'RdYlGn')
mapCountryData(WorldMap,
nameColumnToPlot = '1985 Renewables Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 3.2 - 1985 Renewables Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(renew_tot_energy_con, year == "2008")
mapData <- aggregate(mapData$renewables_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2008 Renewables Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 207 codes from your data successfully matched countries in the map
## 34 codes from your data failed to match with a country code in the map
## 36 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'RdYlGn')
mapCountryData(WorldMap,
nameColumnToPlot = '2008 Renewables Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 3.3 - 2008 Renewables Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(renew_tot_energy_con, year == "2009")
mapData <- aggregate(mapData$renewables_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2009 Renewables Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 207 codes from your data successfully matched countries in the map
## 34 codes from your data failed to match with a country code in the map
## 36 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'RdYlGn')
mapCountryData(WorldMap,
nameColumnToPlot = '2009 Renewables Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 3.4 - 2009 Renewables Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(renew_tot_energy_con, year == "2010")
mapData <- aggregate(mapData$renewables_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2010 Renewables Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 207 codes from your data successfully matched countries in the map
## 34 codes from your data failed to match with a country code in the map
## 36 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'RdYlGn')
mapCountryData(WorldMap,
nameColumnToPlot = '2010 Renewables Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,
mapTitle = "Fig. 3.5 - 2010 Renewables Energy Consumption - Terawatt/Hr")
rm(mapData)
mapData <- filter(renew_tot_energy_con, year == "2019")
mapData <- aggregate(mapData$renewables_consumption, by = list(Country=mapData$country), FUN=sum)
colnames(mapData)[colnames(mapData)=='x'] <- "2019 Renewables Energy Consumption - Terawatt/Hr"
WorldMap <- joinCountryData2Map(mapData,
nameJoinColumn = "Country",
joinCode = "NAME")
## 203 codes from your data successfully matched countries in the map
## 27 codes from your data failed to match with a country code in the map
## 40 codes from the map weren't represented in your data
colourPallette <- RColorBrewer::brewer.pal(11, 'RdYlGn')
mapCountryData(WorldMap,
nameColumnToPlot = '2019 Renewables Energy Consumption - Terawatt/Hr',
catMethod = 'fixedwidth',
colourPalette = colourPallette,
numCats = 100,,
mapTitle = "Fig. 3.6 - 2019 Renewables Energy Consumption - Terawatt/Hr")
For our renewable energy plots, red does not show any correlation to fossil fuel use. It instead represents the lack of renewable energy use. Out renewable fuel visualizations tell a somewhat different story than that of fossil fuels. In Figure 3.1, the United States and Canada are the only countries relatively using these fuels at a large scale. Parts of Europe and Japan can be seen however, that show initial strives towards such use. Later on, citing same years as our fossil fuels, it can be seen that the United States and Canada are using renewable energy much more prominently. Other countries like Brazil, Russia, China, and India are progressing in their use of renewable energy sources as well.
Figure 3.3 and 3.4 Shows a noticeable drawback in use is shown here as well in fossil fuels. It is much more noticeable in our renewable energy figures here due to scaling. This is likely due to the global financial crisis experienced around the globe during this time frame. In addition, they also show that China has overtaken all other countries and become the leading user of renewable energy sources on the planet. Brazil has also become a prominent user becoming an equal rival to the United States. Some counties seem to lag behind, but this may just be in comparison to China’s large growth setting the bar higher and changing the color scale, rather than the notion that they are using less natural resources than past years.
Finally, Fig 3.6 shows this concept even further. Being the country with the highest population on planet, it is not hard to believe they are also a country utilizing the most renewable energy resources as well. This happens to ‘tip the scale’ in their favor in a literal way for this visualization. As such it makes all other countries in this visualization seem as if they are taking a step back, when likely the opposite is true, just in smaller steps compared to China.
Using various tools and packages I was able to take a very large data set with a lot of valuable information and create concise accurate representations that quickly convey a large amount of information. My initial data exploration show that my desire to see an increase in renewable energy source usage has been granted. There has been a steady increase in global usage, and has been rapidly increasing since about 2003. Alternative renewable energy sources have somewhat increases, but negligibly. As such, no other visualizations were used on this category. Contrary to this positive finding, fossil fuels have also been increasing at an even faster rate. This is likely attributed to population and technological advancements, but is still unsettling.
The United States has been one of the most prominent energy consuming countries on the planet since the earlier years of electricity. Even further into history in the 80’s the United States greatly leads in energy usage. This holds true for most of history until China takes over in later years. Other countries ramp up energy use as well, but still are towered over compared to the US and China.
As for renewable energy use, this holds true for China and the United States once again. Canada and the US were early adopters at a larger scale of these resources. By the 80’s many other countries had begun to adopt these practices as well. In later years nearing the 2000s and on, some of the largest energy consuming countries are also the largest users of renewable energy. Brazil is a nice example of a country that stands out in renewable energy usage, where it did not in fossil fuel usage. Once again, this could be due to scaling issues of larger consumers such as China and the US, but it is interesting to see individual countries stand out for clean energy usage.
I was able to address all questions that I had before my visualization analysis. We as a planet certainly are moving in the right direction. We have not taken any visible steps back. However, the mass increase of overall energy use and extreme rate of fossil fuels as our primary energy consumption choice is not perfect. I was hoping to see much more environmentally appealing results. It is slightly disheartening to see that we are not slowing down our use of fossil fuels, and in fact are increasing even more rapidly. It is however understandable, with rising population and technologies. My hopes are that future uses of renewable energy continue this rapidly spiking curve upward to a point that outruns that of fossil fuels until a point of equilibrium and an inevitable continuous downward curve of fossil fuel usage.