#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")
#install.packages("tinytex")
#Load our packages
library(tidyverse) 
library(tidyquant)
library(readxl)
library(lubridate)
library(plotly)
library(esquisse)
library(here)
library(janitor)
library(ggthemes)
library(ggrepel)
library(gt)
library(countrycode)
library(ggplot2)
library(dplyr)
library(ggcharts)
library(leaflet)
library(WDI)
library(gridExtra)
library(wbstats)
str(wb_cachelist, max.level = 1)
## List of 8
##  $ countries    : tibble [304 × 18] (S3: tbl_df/tbl/data.frame)
##  $ indicators   : tibble [16,649 × 8] (S3: tbl_df/tbl/data.frame)
##  $ sources      : tibble [63 × 9] (S3: tbl_df/tbl/data.frame)
##  $ topics       : tibble [21 × 3] (S3: tbl_df/tbl/data.frame)
##  $ regions      : tibble [48 × 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)
new_cache <- wb_cache()
library(readxl)
WDIE <- read_excel("C:/Users/dell/Desktop/susfin/fproject/WDIE.xlsx")
WDIE <- WDIE %>%
  select(-starts_with(c("196","197","198")))
telerenew <- WDIE %>%
  rename(Indicator = "Indicator Code")%>%
  rename(Country = "Country Code")%>%
  pivot_longer('1990':'2021', names_to = "year") %>%
  mutate(year = as.numeric(year)) %>%
  filter(!is.na(value)) %>%
  filter(Indicator %in% c("EG.ELC.RNWX.ZS","EG.ELC.COAL.ZS","EG.ELC.HYRO.ZS","EG.ELC.NGAS.ZS","EG.ELC.NUCL.ZS","EG.ELC.PETR.ZS"))

telerenew$Indicator[telerenew$Indicator == "EG.ELC.COAL.ZS"] <- "elecoal"
telerenew$Indicator[telerenew$Indicator == "EG.ELC.HYRO.ZS"] <- "elehydro"
telerenew$Indicator[telerenew$Indicator == "EG.ELC.NGAS.ZS"] <- "elengas"
telerenew$Indicator[telerenew$Indicator == "EG.ELC.NUCL.ZS"] <- "elenuc"
telerenew$Indicator[telerenew$Indicator == "EG.ELC.PETR.ZS"] <- "eleoil"
telerenew$Indicator[telerenew$Indicator == "EG.ELC.RNWX.ZS"] <- "elerenew"
telerenew$Indicator[telerenew$Indicator == "EG.ELC.RNWX.ZS"] <- "elerenew"
telerenew2 <- telerenew %>%
  pivot_wider(names_from = Indicator, values_from = value)

Global Electricity Energy Sources Trend

telerenew %>% 
  filter (Indicator == "elecoal") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2000")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         157.
telerenew %>% 
  filter (Indicator == "elengas") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2000")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         81.5
telerenew %>% 
  filter (Indicator == "elehydro") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2000")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         76.6
telerenew %>% 
  filter (Indicator == "elenuc") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2000")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         40.5
telerenew %>% 
  filter (Indicator == "eleoil") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2000")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         35.7
telerenew %>% 
  filter (Indicator == "elerenew") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2000")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         4.73
gdf2000<- data.frame (EnergySource  = c("Coal","Natural Gas","Hydroelectric","Oil","Nuclear Energy", "Renewable Energy"),
                  Value = c("157.1","81.5","76.6","40.5","35.7", "4.7"))
telerenew %>% 
  filter (Indicator == "elecoal") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2015")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         173.
telerenew %>% 
  filter (Indicator == "elengas") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2015")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         88.7
telerenew %>% 
  filter (Indicator == "elehydro") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2015")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         64.3
telerenew %>% 
  filter (Indicator == "elenuc") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2015")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         17.4
telerenew %>% 
  filter (Indicator == "eleoil") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2015")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         15.8
telerenew %>% 
  filter (Indicator == "elerenew") %>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>% 
  filter (year =="2015")%>%
  summarize (sum (value))
## # A tibble: 1 × 1
##   `sum(value)`
##          <dbl>
## 1         22.2
gdf2015<- data.frame (EnergySource  = c("Coal","Natural Gas","Hydroelectric","Oil","Nuclear Energy", "Renewable Energy"),
                  Value = c("173.3","88.7","64.3","17.4","15.8", "22.2"))
telerenew5<- telerenew %>% 
  filter(Indicator == "elerenew")%>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>%
  filter (year < "2015")%>%
  group_by(year, Country)%>%
  summarize(sum = sum(value))
telerenew5<- telerenew %>% 
  filter(Indicator == "elecoal")%>%
  filter (Country %in% c("HIC", "LMC","MIC", "UMC", "LIC"))%>%
  filter (year < "2015")%>%
  group_by(year, Country)%>%
  summarize(sum = sum(value))
wbregion <- c("EAS", "ECS", "LCN", "MEA", "NAC", "SAS", "SSF")
renewreg <- wb_data("EG.ELC.RNWX.KH", country = wbregion,
                    start_date = 2015, end_date = 2015)
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")
eaplmirev <- c("IDN", "KHM", "MMR", "MNG", "PHL", "VNM")
reneweaphi <- wb_data("EG.ELC.RNWX.KH", country = eaphi,
                    start_date = 2000, end_date = 2015)
reneweapeumi <- wb_data("EG.ELC.RNWX.KH", country = eapumi,
                    start_date = 2000, end_date = 2015)
reneweaplmi <- wb_data("EG.ELC.RNWX.KH", country = eaplmi,
                    start_date = 2000, end_date = 2015)
reneweaplmirev <- wb_data("EG.ELC.RNWX.KH", country = eaplmirev,
                    start_date = 2000, end_date = 2015)
# create a vector of the desired indicator series
indicators <- c(elecoal, elehydro, elengas, elenuc, eleoil,
                elerenew)
countries <- WDI(country="all", indicator = indicators, 
     start = 1990, end = 2015, extra = TRUE)
# 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))
  1. Through which type of energy is electricity made from in each country/ in each region.
  2. Which country does best in using renewable sources to produce electricity
  3. Which country does the worst in using renewable energy sources to produce electricity?
  4. What is the level of GHG emission & CO2 emission in that country?
  5. What is the CO2 emission from electricity and heat production
  6. (What is the level of PM2.5 comparing the worst and best country)
  7. What is their renewable electricity output?