Data Tidying

Author

Niki Linganur

Data Tidying Assignment

Setup/Loading Packages

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
options(repos = c(CRAN = "https://cran.rstudio.com/"))
install.packages("conflicted")

The downloaded binary packages are in
    /var/folders/yd/c2zm5hrx3z9f72991hsqsbqh0000gn/T//RtmpW8l5Fq/downloaded_packages
library(conflicted)
conflict_prefer("filter", "dplyr")
[conflicted] Will prefer dplyr::filter over any other package.
conflict_prefer("lag", "dplyr")
[conflicted] Will prefer dplyr::lag over any other package.
options(repos = c(CRAN = "https://cran.rstudio.com/"))
install.packages("janitor")

The downloaded binary packages are in
    /var/folders/yd/c2zm5hrx3z9f72991hsqsbqh0000gn/T//RtmpW8l5Fq/downloaded_packages
library(janitor) 
library(countrycode)
green_debt <- read_csv( "https://opendata.arcgis.com/datasets/8e2772e0b65f4e33a80183ce9583d062_0.csv") 
Rows: 355 Columns: 42
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (12): Country, ISO2, ISO3, Indicator, Unit, Source, CTS_Code, CTS_Name, ...
dbl (30): ObjectId, F1985, F1986, F1987, F1990, F1991, F1992, F1993, F1994, ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Question 1

library(ggplot2)
library(countrycode)
library(dplyr)
library(tidyr)

reen_debt <- green_debt |>
  clean_names() |>
  mutate(region = countrycode(iso2, "iso2c", "continent"), 
         .before = iso2)

green_debt_cumulate <- reen_debt |>
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "fiscal_year", 
    values_to = "issuance_bn_usd",
    values_drop_na = TRUE
    )|>
  group_by(region) |>
  summarize(cumulative_issuance = sum(issuance_bn_usd, na.rm = TRUE)) |>
  filter(!is.na(region)) |>
  ungroup()

ggplot(green_debt_cumulate, aes(x = region, y = cumulative_issuance, fill = region)) +
  geom_text(aes(label = sprintf("%.2f", cumulative_issuance), vjust = -0.5)) +
  geom_col() +
  labs(
    title = "Cumulative issuance of green bonds by region", 
    x = "Region", 
    y = "Issurance of green bonds (Billions of USD)",
    caption = "Author: Niki Linganur"
    ) +
  theme(plot.title = element_text(face = "bold"),
        plot.caption = element_text(hjust = 1)) +
  scale_fill_manual(values = c("#FF5733", "#FFBD33", "#6CFF33", "#338BFF", "#D233FF")) # Change colors as desired

Question 2

green_debt_toi <- green_debt |> 
  clean_names() |>
  filter(type_of_issuer != "Not Applicable")

green_debt_toi <- green_debt_toi |>
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "fiscal_year", 
    values_to = "issuance_bn_usd",
    names_transform = readr::parse_number,
    values_drop_na = TRUE
    )
library(ggplot2)
library(dplyr)

green_debt_toi |>
  filter(fiscal_year >= 2010) |>
  ggplot(aes(x = fiscal_year, y = issuance_bn_usd, fill = type_of_issuer)) +
  geom_col() +
  labs(
    title = "Green bond issuance by different types of issuers from 2010-2022", 
    x = "Year", 
    y = "Issuance of green bonds (Billions of USD)",
    caption = "Author: Niki Linganur"
  ) +
  theme(
    plot.title = element_text(face = "bold"), 
    axis.text.x = element_text(angle = 30, hjust = 1)
  ) +
  scale_fill_manual(values = c("#FF5733", "#FFBD33", "#6CFF33", "#338BFF", "#D233FF", "#FF6EFF", "#33FFD2")) 

Factoid: Over the years, non financial corporations are increasingly the issuers of green bonds.

library(ggplot2)
library(dplyr)

green_debt_toi_cumulate <- green_debt_toi |>
  group_by(type_of_issuer) |>
  summarize(cumulative_issuance = sum(issuance_bn_usd)) |>
  ungroup()

ggplot(green_debt_toi_cumulate, aes(x = type_of_issuer, y = cumulative_issuance, fill = type_of_issuer)) +
  geom_text(aes(label = sprintf("%.2f", cumulative_issuance), vjust = -0.5), color = "black", size = 3) +
  geom_col() +
  labs(
    title = "Cumulative issuance of green bonds by type of issuer", 
    x = "Type of issuer", 
    y = "Issuance of green bonds (Billions of USD)",
    caption = "Author: Niki Linganur"
  ) +
  theme(
    plot.title = element_text(face = "bold"), 
    axis.text.x = element_text(angle = 30, hjust = 1),
    plot.caption = element_text(hjust = 1)
  ) +
  scale_fill_brewer(palette = "YlGn") 

Factoid: Local and State governments have issued the least amount of green bonds (in billions of USD).

Question 3

Part a

green_debt_uop <- green_debt |> 
  clean_names() |>
  filter(use_of_proceed != "Not Applicable")|>
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "fiscal_year", 
    values_to = "issuance_bn_usd",
    values_drop_na = TRUE
  )|>
  select(use_of_proceed, fiscal_year, issuance_bn_usd)|>
  filter(!grepl("e", issuance_bn_usd))

unique(green_debt_uop$use_of_proceed)
 [1] "Access to Essential Services"                                                      
 [2] "Acquiring and distribution of vaccine"                                             
 [3] "Acquisition"                                                                       
 [4] "Affordable Basic Infrastructure"                                                   
 [5] "Agriculture"                                                                       
 [6] "Alternative Energy"                                                                
 [7] "Aquatic Biodiversity Conservation"                                                 
 [8] "Capital expenditure"                                                               
 [9] "Capital expenditure/Financing expenses"                                            
[10] "Carbon reduction through reforestation and avoided deforestation"                  
[11] "China Urban Construction"                                                          
[12] "Circular Economy Adapted/Eco-efficient Products, Production Technologies/Processes"
[13] "Clean Transport"                                                                   
[14] "Climate Change Adaptation"                                                         
[15] "E-education programs - Education Projects"                                         
[16] "Economic Development"                                                              
[17] "Electric & Public Power"                                                           
[18] "Eligible Green Projects"                                                           
[19] "Employee stock ownership plan"                                                     
[20] "Energy Efficiency"                                                                 
[21] "Environmental Protection Projects"                                                 
[22] "Environmentally Sustainable Products"                                              
[23] "Equipment Upgrade/Construction"                                                    
[24] "Financing of Subordinated Loan"                                                    
[25] "Funding new technologies to reduce GHS emissions"                                  
[26] "Gas"                                                                               
[27] "General Purpose"                                                                   
[28] "General Purpose/Acquisition"                                                       
[29] "General Purpose/Refinance"                                                         
[30] "General Purpose/Working Capital"                                                   
[31] "Green Construction/Buildings"                                                      
[32] "Higher Education"                                                                  
[33] "Industrial Development"                                                            
[34] "Infrastructure"                                                                    
[35] "Land Preservation"                                                                 
[36] "Merger or Acquisition"                                                             
[37] "Other"                                                                             
[38] "Other Education"                                                                   
[39] "Other Housing"                                                                     
[40] "Other Public Service"                                                              
[41] "Other Transportation"                                                              
[42] "Pandemic"                                                                          
[43] "Pollution Control"                                                                 
[44] "Pollution Prevention & Control"                                                    
[45] "Production/Supply of Cannabis"                                                     
[46] "Project Finance"                                                                   
[47] "Property Expendit (acquisit/development)"                                          
[48] "Redeem Existing Bonds or Securities"                                               
[49] "Refinance/Financing expenses"                                                      
[50] "Renewable Energy Projects"                                                         
[51] "Repay Bank Loan or Bridge Financing"                                               
[52] "Repay Intercompany Debt"                                                           
[53] "Ship finance"                                                                      
[54] "Social Housing/Affordable Housing"                                                 
[55] "Socioeconomic Advancement And Empowerment"                                         
[56] "Solar projects"                                                                    
[57] "Sustainable Development Projects"                                                  
[58] "Sustainable Economic Growth"                                                       
[59] "Sustainable Forestry"                                                              
[60] "Sustainable Management of Land Use"                                                
[61] "Sustainable Management of Living Natural Resources"                                
[62] "Sustainable Transport"                                                             
[63] "Sustainable Water or Wastewater management"                                        
[64] "Terrestrial Biodiversity Conservation"                                             
[65] "The Belt and Road Initiative"                                                      
[66] "Waste Management"                                                                  
[67] "Water & Sewer"                                                                     
[68] "Wind projects"                                                                     
[69] "Working capital"                                                                   
library(ggplot2)


# Assuming green_debt_uop is your data frame
# Assuming issuance_bn_usd is numeric, if not, convert it to numeric

# Convert issuance_bn_usd to numeric if it's not already numeric
green_debt_uop$issuance_bn_usd <- as.numeric(green_debt_uop$issuance_bn_usd)

# Plotting
ggplot(green_debt_uop, aes(x = use_of_proceed, y = issuance_bn_usd, fill = fiscal_year)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.8)) + # Adjust the width as needed
  labs(title = "Issuance Amounts by Use of Proceeds",
       x = "Use of Proceeds",
       y = "Issuance Amount (in billion USD)",
       fill = "Fiscal Year") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "bottom") + # Move legend to the bottom
  coord_flip() + # Flip coordinates for better readability
  scale_y_continuous(labels = scales::comma) # Add comma separator to y-axis labels for better readability

The green bonds proceeds are used in the 69 different areas listed above and in the graph above.

Part b

green_debt_pc <- green_debt |> 
  clean_names() |>
  filter(principal_currency != "Not Applicable") |>
  pivot_longer(
    cols = matches("f\\d{4}"),
    names_to = "fiscal_year", 
    values_to = "issuance_bn_usd",
    values_drop_na = TRUE
  )|>
  select(principal_currency, fiscal_year, issuance_bn_usd)|>
  filter(!grepl("e", issuance_bn_usd))

unique(green_debt_pc$principal_currency)
 [1] "Argentinian Peso"                         
 [2] "Argentinian Unidades de Valor Adquisitivo"
 [3] "Australian Dollar"                        
 [4] "Bangladeshi Taka"                         
 [5] "Brazilian Real"                           
 [6] "British Pound"                            
 [7] "Canadian Dollar"                          
 [8] "Chilean Peso"                             
 [9] "Chilean Unidad de Fomento"                
[10] "Chinese Yuan"                             
[11] "Colombian Peso"                           
[12] "Czech Koruna"                             
[13] "Danish Krone"                             
[14] "Deutsche Mark"                            
[15] "Euro"                                     
[16] "European Currency Unit"                   
[17] "Fijian Dollar"                            
[18] "Hong Kong Dollar"                         
[19] "Hungarian Forint"                         
[20] "Icelandic Krona"                          
[21] "Indian Rupee"                             
[22] "Indonesian Rupiah"                        
[23] "Japanese Yen"                             
[24] "Kazakhstani Tenge"                        
[25] "Macanese Pataca"                          
[26] "Malaysian Ringgit"                        
[27] "Mexican Peso"                             
[28] "Mexican Unidad de Inversion"              
[29] "Moroccan Dirham"                          
[30] "Namibian Dollar"                          
[31] "New Zealand Dollar"                       
[32] "Nigerian Naira"                           
[33] "Norwegian Krone"                          
[34] "Peruvian Sol"                             
[35] "Philippine Peso"                          
[36] "Polish Zloty"                             
[37] "Romanian Leu"                             
[38] "Russian Ruble"                            
[39] "Singapore Dollar"                         
[40] "South African Rand"                       
[41] "South Korean Won"                         
[42] "Sri Lankan Rupee"                         
[43] "Swedish Krona"                            
[44] "Swiss Franc"                              
[45] "Taiwanese Dollar"                         
[46] "Thai Baht"                                
[47] "Turkish Lira"                             
[48] "Ukrainian Hryvnia"                        
[49] "US Dollar"                                
[50] "Vietnamese Dong"                          
library(ggplot2)

# Assuming green_debt_pc is your data frame
# Assuming issuance_bn_usd is numeric, if not, convert it to numeric

# Convert issuance_bn_usd to numeric if it's not already numeric
green_debt_pc$issuance_bn_usd <- as.numeric(green_debt_pc$issuance_bn_usd)

# Plotting
ggplot(green_debt_pc, aes(x = principal_currency, y = issuance_bn_usd, fill = fiscal_year)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Issuance Amounts by Principal Currency",
       x = "Principal Currency",
       y = "Issuance Amount (in billion USD)",
       fill = "Fiscal Year") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "bottom") + # Move legend to the bottom
  scale_y_continuous(labels = scales::comma) # Add comma separator to y-axis labels for better readability

In 2022, 50 curriencies were used for green bond issuances, however since there have not been any green bond issuance prior to that, we cannot definitively calculate the change over a time period.