#install.packages("wbstats")
#install.packages("tidyverse")
#install.packages("ggcharts")
#install.packages("esquisse")
#install.packages("readxl")
#install.packages("plotly")
#install.packages("viridis")
#install.packages("hrbrthemes")
#install.packages("gridExtra")

Load World Bank API Database

library(wbstats)
str(wb_cachelist, max.level = 1)
## List of 8
##  $ countries    : tibble [297 × 18] (S3: tbl_df/tbl/data.frame)
##  $ indicators   : tibble [16,643 × 8] (S3: tbl_df/tbl/data.frame)
##  $ sources      : tibble [62 × 9] (S3: tbl_df/tbl/data.frame)
##  $ topics       : tibble [21 × 3] (S3: tbl_df/tbl/data.frame)
##  $ regions      : tibble [42 × 4] (S3: tbl_df/tbl/data.frame)
##  $ income_levels: tibble [7 × 3] (S3: tbl_df/tbl/data.frame)
##  $ lending_types: tibble [4 × 3] (S3: tbl_df/tbl/data.frame)
##  $ languages    : tibble [23 × 3] (S3: tbl_df/tbl/data.frame)
library(wbstats)
new_cache <- wb_cache()

Define variable Electricity production from coal sources (% of total)

elecoal <- wb_data("EG.ELC.COAL.ZS", start_date = 2014, end_date = 2014)

Differentiate Database based on region: East Asia & Pacific, Europe & Central Asia, Latin America & Caribbean, Middle East & North Africa, North America, South Asia, Sub-Saharan Africa

Year 2015

wbregion <- c("EAS", "ECS", "LCN", "MEA", "NAC", "SAS", "SSF")

Electricity Produced by Coal

coalreg <- wb_data("EG.ELC.COAL.ZS", country = wbregion,
                    start_date = 2015, end_date = 2015)

Graph rank coal by region

plot1 <- coalreg %>%
 filter(date >= 2015L & date <= 2015L) %>%
 ggplot() +
  aes(x = country, y = EG.ELC.COAL.ZS) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Regions",
    y = "Electricity Production by Coal",
    subtitle = "Electricity Production by Coal",
    caption = "By Region Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))

Electricity production from renewable sources, excluding hydroelectric (kWh)

renewreg <- wb_data("EG.ELC.RNWX.KH", country = wbregion,
                    start_date = 2015, end_date = 2015)

Graph renewable energy by region

plot2<- renewreg %>%
 filter(date >= 2015L & date <= 2015L) %>%
 ggplot() +
  aes(x = country, y = EG.ELC.RNWX.KH/1000000000) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Regions",
    y = "Electricity Production by Renewable in Billion kwh",
    subtitle = "Electricity Production by Renewable",
    caption = "By Region Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))
grid.arrange(plot1, plot2, nrow = 1)

South Asia as a region that produces most of the electricity use coal. South Asia is one of the regions that uses the least renewable energy to produce electricity.

Differentiate Database based on income: High income, Low & middle income, Middle Income, Upper middle income, Middle income, Lower middle income, Low income

birth <- "SP.DYN.CBRT.IN"
infmort <- "SP.DYN.IMRT.IN"
net <-"IT.NET.USER.ZS"
lifeexp <- "SP.DYN.LE00.IN"
forest <- "AG.LND.FRST.ZS"
mobile <- "IT.CEL.SETS.P2"
pop <- "SP.POP.TOTL"
tour <- "ST.INT.RCPT.CD"
import <- "TM.VAL.MRCH.XD.WD"
export <- "TX.VAL.MRCH.XD.WD"
# create a vector of the desired indicator series
indicators <- c(birth, infmort, net, lifeexp, forest,
                mobile, pop, tour, import, export)

countries <- WDI(country="all", indicator = indicators, 
     start = 1998, end = 2018, extra = TRUE)

## rename columns for each of reference
countries <- rename(countries, birth = SP.DYN.CBRT.IN, 
       infmort = SP.DYN.IMRT.IN, net  = IT.NET.USER.ZS,
       lifeexp = SP.DYN.LE00.IN, forest = AG.LND.FRST.ZS,
       mobile = IT.CEL.SETS.P2, pop = SP.POP.TOTL, 
       tour = ST.INT.RCPT.CD, import = TM.VAL.MRCH.XD.WD,
       export = TX.VAL.MRCH.XD.WD)

# convert geocodes from factors into numerics

countries$lng <- as.numeric(as.character(countries$longitude))
countries$lat <- as.numeric(as.character(countries$latitude))

# Remove groupings, which have no geocodes
countries <- countries %>%
   filter(!is.na(lng))
# filter to 1998 and select relevant variables
wdi98 <- countries %>% filter(year == 2015)%>%
  select(country,year, pop, income, lat, lng)%>%
  mutate(popM = pop/1000000)

# Create a color palette with bins.
inccols = colorFactor( palette= c("dark red", "#FF7F7F", "orange", "#7E7E7E"), 
                       levels = c("High income", "Upper middle income", 
                                  "Lower middle income", "Low income"))

#order income levels
wdi98$income <- ordered(wdi98$income, levels = c("High income", "Upper middle income", 
                                  "Lower middle income", "Low income"))
#create leaflet map for 1998
w98 <- leaflet(data = wdi98) %>%
  addTiles() %>% setView(lng = 10, lat =0, zoom = 1.5) %>%
  addCircleMarkers(~lng, ~lat,popup = ~as.character(country),color = ~ inccols(income),
                   radius = ~sqrt(popM), stroke = FALSE, fillOpacity = .9)%>%
  addLegend(pal = inccols, values = ~income,opacity=0.9,
            title = "Income Category", position = "bottomleft" ) %>%
  addControl("Income and Population in 2015", position = "bottomright");w98

High income group (1) aggregate. High-income economies are those in which 2021 GNI per capita was more than $13,205. Low and middle-income group (2) aggregate. Low and middle-income economies are those in which 2021 GNI per capita was less than $13,205.

Upper middle income group (3) aggregate. Upper-middle-income economies are those in which 2021 GNI per capita was between $4,256 and $13,205. Middle income group (4) aggregate. Middle-income economies are those in which 2021 GNI per capita was between $1,086 and $13,205. Lower middle income group (5) aggregate. Lower-middle-income economies are those in which 2021 GNI per capita was between $1,086 and $4,255. Low income group (6) aggregate. Low-income economies are those in which 2021 GNI per capita was $1,085 or less. High income group (1) and Low and middle-income group (2) are two mutually exclusive income groups. All the other income groups (3) - (6) are a subset of the Low and middle-income group (2). Lower middle income group (5) is a union of Upper middle income group (3) and Low income group (6), and Middle income group (4) is a subset of Upper middle income group (3).

Year 2015

wbincome <- c("HIC", "LMC", "MIC", "UMC", "LMY", "LIC")
coalinc <- wb_data("EG.ELC.COAL.ZS", country = wbincome,
                    start_date = 2015, end_date = 2015)

Graph coal by income groups

plot3<- ggplot(coalinc) +
  aes(x = country, y = EG.ELC.COAL.ZS) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Income Groups",
    y = "Electricity Production by Coal",
    subtitle = "Electricity Production by Coal",
    caption = "By Income Groups Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))

Renewable Energy

renewinc <- wb_data("EG.ELC.RNWX.KH", country = wbincome,
                    start_date = 2015, end_date = 2015)

Graph renewable energy by income groups

plot4<-ggplot(renewinc) +
  aes(x = country, y = EG.ELC.RNWX.KH/1000000000) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Income Groups",
    y = "Electricity Production by Renewable Energy",
    subtitle = "Electricity Production by Renewable Energy",
    caption = "By Income Groups Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))

hydroelectric sources

hydroinc <- wb_data("EG.ELC.HYRO.ZS", country = wbincome,
                    start_date = 2015, end_date = 2015)

Graph hydroelectric sources by income groups

plot4.1<-ggplot(hydroinc) +
  aes(x = country, y = EG.ELC.HYRO.ZS) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Income Groups",
    y = "Electricity Production by hydroelectric sources",
    subtitle = "Electricity Production by hydroelectric sources",
    caption = "By Income Groups Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))

natural gas

ngasinc <- wb_data("EG.ELC.NGAS.ZS", country = wbincome,
                    start_date = 2015, end_date = 2015)

Graph natural gas by income groups

plot4.2<-ggplot(ngasinc) +
  aes(x = country, y = EG.ELC.NGAS.ZS) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Income Groups",
    y = "Electricity Production by natural gas sources",
    subtitle = "Electricity Production by natural gas sources",
    caption = "By Income Groups Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))

oil

oilinc <- wb_data("EG.ELC.PETR.ZS", country = wbincome,
                    start_date = 2015, end_date = 2015)

Graph natural gas by income groups

plot4.3<-ggplot(oilinc) +
  aes(x = country, y = EG.ELC.PETR.ZS) +
  geom_bar(stat="identity", width=.5, fill="darkgreen")+
  labs(
    x = "Income Groups",
    y = "Electricity Production by oil sources",
    subtitle = "Electricity Production by oil sources",
    caption = "By Income Groups Year 2015"
  ) +
  theme_minimal()+
  theme(axis.text.x = element_text(angle=45, hjust=1))+
  scale_x_discrete(labels=c("East Asia\n& Pacific", "Europe \n& Central Asia", "Latin America \n& Caribbean", "Middle East \n& North Africa", "North America", "South Asia", "Sub-Saharan Africa"))
grid.arrange(plot3, plot4,plot4.1, plot4.3, nrow = 2)
## Warning: Removed 1 rows containing missing values (position_stack).
## Removed 1 rows containing missing values (position_stack).
## Removed 1 rows containing missing values (position_stack).

Focus on East-Asia Pacific Region

High Income Countries Australia, Brunei, Guam, Hong Kong SAR, China, Japan, Korea, Macao SAR, China, Northern Mariana Islands, New Caledonia, Nauru, New Zealand, French Polynesia, Singapore

Low Income Country: Dem. People’s Rep. Korea

Low Middle Income Countries: Micronesia, Indonesia, Cambodia, Kiribati, Lao PDR, Myanmar, Mongolia, Philippines, Papua New Guinea, Solomon Islands, Timor-Leste, Vietnam, Vanuatu, Samoa

Upper Middle Income Countries: American Samoa, China, Fiji, Marshall Islands, Malaysia, Palau, Thailand, Tonga, Tuvalu

eaphi <- c("AUS", "BRN", "GUM", "HKG", "JPN", "KOR", "MAC", "MNP", "NCL", "NRU", "NZL", "PYF", "SGP")
eapli <- c("PRK")
eaplmi <- c("FSM", "IDN", "KHM", "KIR", "LAO", "MMR", "MNG", "PHL", "PNG", "SLB", "TLS", "VNM", "VUT", "WSM")
eapumi <- c("ASM", "CHN", "FJI", "MHL", "MYS", "PLW", "THA", "TON", "TUV")

Graph East Asia Pacific High Income Countries Electricity Produced by Renewable Energy Year 2000 to 2015 Japan does the best producing electricity with renewable energy.

reneweaphi <- wb_data("EG.ELC.RNWX.KH", country = eaphi,
                    start_date = 2000, end_date = 2015)
plot5<-ggplot(reneweaphi, aes(x = date, y = EG.ELC.RNWX.KH/1000000000, color = country, shape = country, group = country)) +
  geom_point() + 
  geom_line() +
  labs(title = "Electricity Produced by Renewable Energy") +
  xlab("Year" ) +
  ylab("Electricity production from renewable sources in billion (kWh)") +
  scale_x_discrete(breaks=seq(2000,2015,2)) +
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())
plot5
## Warning: The shape palette can deal with a maximum of 6 discrete values because
## more than 6 becomes difficult to discriminate; you have 13. Consider
## specifying shapes manually if you must have them.
## Warning: Removed 144 rows containing missing values (geom_point).
## Warning: Removed 96 row(s) containing missing values (geom_path).

reneweaplmi <- wb_data("EG.ELC.RNWX.KH", country = eaplmi,
                    start_date = 2000, end_date = 2015)

Based on the information from the data, choose countries without missing data to conduct analysis

eaplmirev <- c("IDN", "KHM", "MMR", "MNG", "PHL", "VNM")

Graph East Asia Pacific Low Middle Income Countries Electricity Produced by Renewable Energy Year 2000 to 2015

reneweaplmirev <- wb_data("EG.ELC.RNWX.KH", country = eaplmirev,
                    start_date = 2000, end_date = 2015)
plot6<-ggplot(reneweaplmirev, aes(x = date, y = EG.ELC.RNWX.KH/1000000000, color = country, shape = country, group = country)) +
  geom_point() + 
  geom_line() +
  labs(title = "Electricity Produced by Renewable Energy") +
  xlab("Year") +
  ylab("Electricity production from renewable sources in billion (kWh)") +
  scale_x_discrete(breaks=seq(2000,2015,2)) +
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())
plot6

Indonesia and Philippines is doing better with producing electricity with renewable energy in the East Asia Pacific Low Middle Income Countries.

Renewable energy consumption (% of total final energy consumption) EG.FEC.RNEW.ZS - Graph East Asia Pacific Low Middle Income Countries Electricity Produced by Renewable Energy

reconeaplmirev <- wb_data("EG.FEC.RNEW.ZS", country = eaplmirev,
                    start_date = 1990, end_date = 2015)

plot7<-ggplot(reconeaplmirev, aes(x = date, y = EG.FEC.RNEW.ZS, color = country, shape = country, group = country)) +
  geom_point() + 
  geom_line() +
  labs(title = "Electricity Consumption by Renewable Energy") +
  xlab("Year") +
  ylab("Electricity consumption from renewable sources (kWh)") +
  scale_x_discrete(breaks=seq(1990,2015,2)) +
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())
plot7
## Warning: Removed 5 rows containing missing values (geom_point).
## Warning: Removed 5 row(s) containing missing values (geom_path).

The consumption of renewable energy level is decreasing over the year for all countries. One question arise, is this a result from overall energy consumption reduction, or only for the renewable energy? Electricity production from renewable sources, excluding hydroelectric (% of total) EG.ELC.RNWX.ZS

reconeaplmirevper <- wb_data("EG.ELC.RNWX.ZS", country = eaplmirev,
                    start_date = 1990, end_date = 2015)
plot8<-ggplot(reconeaplmirevper, aes(x = date, y = EG.ELC.RNWX.ZS, color = country, shape = country, group = country)) +
  geom_point() + 
  geom_line() +
  labs(title = "Electricity Production by Renewable Energy") +
  xlab("Year") +
  ylab("Electricity Production from renewable sources (% of total)") +
  scale_x_discrete(breaks=seq(1990,2015,2)) +
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())
plot8
## Warning: Removed 5 rows containing missing values (geom_point).
## Warning: Removed 5 row(s) containing missing values (geom_path).

The graph shows that the percentage change is not big. To corroborate this, the graph below shows the Fossil fuel energy consumption (% of total) EG.USE.COMM.FO.ZS

coalconeaplmirev <- wb_data("EG.USE.COMM.FO.ZS", country = eaplmirev,
                    start_date = 1990, end_date = 2015)
plot9<-ggplot(coalconeaplmirev, aes(x = date, y = EG.USE.COMM.FO.ZS, color = country, shape = country, group = country)) +
  geom_point() + 
  geom_line() +
  labs(title = "Electricity Consumption of Fossil Fuel(% of total)") +
  xlab("Year") +
  ylab("Electricity consumption from Fossil Fuel(% of total)") +
  scale_x_discrete(breaks=seq(1990,2015,2)) +
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())
plot9
## Warning: Removed 12 rows containing missing values (geom_point).
## Warning: Removed 12 row(s) containing missing values (geom_path).

This shows that over the years, the percentage fossil fuel energy consumption increased over the years. With Vietnam being one of the fastest growing consumer. Indonesia and Philippines high on energy use too.

##View Data

gdp_data_idn <- wb(country = "IDN", indicator = "NY.GDP.PCAP.CD",startdate = 2000, enddate = 2015)
## Warning: `wb()` was deprecated in wbstats 1.0.0.
## ℹ Please use `wb_data()` instead.
nrow(gdp_data_idn)  
## [1] 16
ncol(gdp_data_idn) 
## [1] 7
summary(gdp_data_idn) # Prints a statistical summary of the data frame variables (columns)
##     iso3c               date               value        indicatorID       
##  Length:16          Length:16          Min.   : 748.3   Length:16         
##  Class :character   Class :character   1st Qu.:1129.1   Class :character  
##  Mode  :character   Mode  :character   Median :2013.4   Mode  :character  
##                                        Mean   :2168.3                     
##                                        3rd Qu.:3371.7                     
##                                        Max.   :3694.4                     
##   indicator            iso2c             country         
##  Length:16          Length:16          Length:16         
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
## 
head(gdp_data_idn) # Prints the first few rows
tail(gdp_data_idn)   # Prints the last few rows

###Plot Indonesia GDP graph

ggplot(gdp_data_idn, aes(x = date, y = value)) + 
  geom_col(fill = "darkgreen") +
  geom_point(color = "grey3")

Further Research:

  1. Topic: What question in sustainable finance would you like to shed light on?
  1. Data: What data do you plan on using to inform this analysis? Remember, we seldom have the data we need. We have to make do with the data that exists and is available to us. How can the data that we have shed light on the topic of interest?
  1. Data Analysis: What kind of questions would your data analysis try to answer?
  1. Audience: The purpose of the final project is to give you a professional quality project to show to potential employers. What potential employer(s) are you targeting?
  1. How the level of electricity usage is impacted by ICT?
  2. 2016 ICT network operators carbon emission cross country data.
  3. How the level of electricity usage (energy usage) is impacted by Covid 19? Carbon emission level cross country

Related Articles: How is the level of electricity usage (energy usage) impacted by Covid 19? Digitalization and energy consumption. Does ICT reduce energy demand? Comparison of the energy, carbon and time costs of videoconferencing and in-person meetings Assessing ICT global emissions footprint: Trends to 2040 & recommendations The Energy and Carbon Footprint of the Global ICT and E&M Sectors 2010–2015 An outlook on the global development of renewable and sustainable energy at the time of COVID-19