#Create folder path for data access
folder_path <- partial(here, "03_data_processed")
folder_path() %>% list.files()
## [1] "country_features_2022-10.csv"    "emissions_dataset_full.csv"     
## [3] "emissions_dataset.csv"           "Green_bond_full_dataset.csv"    
## [5] "imf_weo_by_country_2022_oct.csv"
#Import data
emissions_dataset <- folder_path("emissions_dataset.csv") %>%
  read_csv()
## New names:
## Rows: 2820 Columns: 32
## ── Column specification
## ────────────────────────────────────────────────────────
## Delimiter: "," chr (3): country_name, iso3c, em_dm dbl (29): ...1, year,
## gdp_usd_current_prices, gdp_ppp_current_prices, gdp_pc...
## ℹ 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.
## • `` -> `...1`
emissions_dataset_full <- folder_path("emissions_dataset_full.csv") %>%
  read_csv()
## New names:
## Rows: 6702 Columns: 32
## ── Column specification
## ────────────────────────────────────────────────────────
## Delimiter: "," chr (1): iso3c dbl (31): ...1, year, gdp_usd_current_prices,
## gdp_ppp_current_prices, gdp_pc...
## ℹ 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.
## • `` -> `...1`
imf_weo_by_country_2022 <- folder_path("imf_weo_by_country_2022_oct.csv") %>%
  read_csv()
## New names:
## Rows: 414000 Columns: 10
## ── Column specification
## ────────────────────────────────────────────────────────
## Delimiter: "," chr (7): country_name, iso3c, short_name_unit, short_name,
## short_unit, categ... dbl (3): ...1, year, value
## ℹ 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.
## • `` -> `...1`
country_features_2022 <- folder_path("country_features_2022-10.csv") %>%
  read_csv()
## New names:
## Rows: 217 Columns: 9
## ── Column specification
## ────────────────────────────────────────────────────────
## Delimiter: "," chr (4): country_name, iso3c, wb_income_group, wb_region dbl
## (5): ...1, debt_gross_percent_of_gdp, nominal_gdp_bn_ppp, nominal_gdp_pe...
## ℹ 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.
## • `` -> `...1`
Green_bond_full_dataset <- folder_path("Green_bond_full_dataset.csv") %>%
  read_csv()
## New names:
## Rows: 5006 Columns: 21
## ── Column specification
## ────────────────────────────────────────────────────────
## Delimiter: "," chr (18): description, maturity_date, coupon_class, currency,
## ESG_bond_type,... dbl (3): ...1, amount_outstanding_usd, issued_amount_usd
## ℹ 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.
## • `` -> `...1`
#Get subsets of Green_bond_full_dataset
green_bond_issued_amount_10 <- Green_bond_full_dataset %>%
    group_by(country_of_issue) %>%
    summarize(issued_amount_usd = sum(issued_amount_usd)) %>%
    arrange(desc(issued_amount_usd)) %>%
    slice (1:10)

green_bond_outstanding_amount_10 <- Green_bond_full_dataset %>%
    group_by(country_of_issue) %>%
    summarize(amount_outstanding_usd = sum(amount_outstanding_usd)) %>%
    arrange(desc(amount_outstanding_usd)) %>%
    slice (1:10)
#Define gppr_theme() function

theme_gppr <- function(){ 
    font <- "Georgia"   #assign font family up front
    
    theme_pander() %+replace%    #replace elements we want to change
    
    theme(
    
      #text elements
      plot.title = element_text(             #title
                   family = font,            #set font family
                   size = 16,                #set font size
                   face = 'bold',            #bold typeface
                   hjust = 0,                #left align
                   vjust = 0),               #raise slightly
      
      plot.subtitle = element_text(          #subtitle
                   family = font,            #font family
                   size = 12),               #font size
      
      plot.caption = element_text(           #caption
                   family = font,            #font family
                   size = 9,                 #font size
                   hjust = 1),               #right align
      
      axis.title = element_text(             #axis titles
                   family = font,            #font family
                   size = 10),               #font size
      
      axis.text = element_text(              #axis text
                   family = font,            #axis famuly
                   size = 9),                #font size
      
      axis.text.x = element_text(            #margin for axis text
                    margin=margin(5, b = 10))
      
    )
}
#Horizontal barplot in terms of Top 10 countries with the highest issuance amount of green bonds
green_bond_issued_amount_10 %>%
  ggplot(aes(fct_reorder(country_of_issue, issued_amount_usd),issued_amount_usd)) +
  geom_col() + 
  coord_flip() +
  scale_y_continuous(labels = comma) +
  scale_x_discrete (guide = guide_axis(n.dodge=1.75)) +
  labs(
    x = "",
    y = "Issued amount of Green bonds in USD",
    title = "Who are the largest issuers of green bonds?",
    subtitle = "Top 10 countries with the highest issuance amount of green bonds",
    caption = "Data source: Refinitiv"
    )+
  theme_gppr()

#Horizontal barplot in terms of top 10 countries with the highest outstanding amount of green bonds

green_bond_outstanding_amount_10 %>%
  ggplot(aes(fct_reorder(country_of_issue, amount_outstanding_usd),amount_outstanding_usd)) +
  geom_col() + 
  coord_flip() +
  scale_y_continuous(labels = comma) +
  scale_x_discrete (guide = guide_axis(n.dodge=1.75)) +
  labs(
    x = "",
    y = "Outstanding amount of Green bonds in USD",
    title = "Who are the largest issuers of green bond?",
    subtitle = "Top 10 countries with the highest outstanding amount of green bonds",
    caption = "Data source: Refinitiv"
    )+
  theme_gppr()

#Get a subset of Green_bond_full_dataset
green_bond_issued_and_outstanding <- Green_bond_full_dataset %>%
    group_by(country_of_issue) %>%
    summarize(issued_amount_usd = sum(issued_amount_usd),
        amount_outstanding_usd = sum(amount_outstanding_usd)) %>%
    arrange(desc(amount_outstanding_usd))
#Lollipop plot to stress the differences between issue amount and outstanding amount of green bonds

ggplot(green_bond_issued_and_outstanding) +
  geom_segment( aes(x=country_of_issue, xend=country_of_issue, y=amount_outstanding_usd, yend=issued_amount_usd), color="grey") +
  geom_point( aes(x=country_of_issue, y=amount_outstanding_usd), color=rgb(0.2,0.7,0.1,0.5), size=3 ) +
  geom_point( aes(x=country_of_issue, y=issued_amount_usd), color=rgb(0.7,0.2,0.1,0.5), size=3 ) +
  coord_flip()+
  theme_grey() +
  theme(
    legend.position = "none",
  ) +
  xlab("") +
  ylab("Amount of Green Bonds in USD")

#join country_features_2022 and get a subset of Green_bond_full_dataset

green_bond_country_features <- Green_bond_full_dataset %>%
    left_join(country_features_2022, by = "iso3c") %>%
    group_by(country_of_issue, wb_income_group, wb_region)%>%
    summarize(issued_amount_usd_mean = mean(issued_amount_usd),
        amount_outstanding_usd_mean = mean(amount_outstanding_usd))
## `summarise()` has grouped output by 'country_of_issue', 'wb_income_group'. You
## can override using the `.groups` argument.
green_bond_country_features 
## # A tibble: 56 × 5
## # Groups:   country_of_issue, wb_income_group [56]
##    country_of_issue wb_income_group wb_region                 issued_a…¹ amoun…²
##    <chr>            <chr>           <chr>                          <dbl>   <dbl>
##  1 Argentina        Upper Middle    Latin America & Caribbean     2.37e7  2.19e7
##  2 Australia        High            East Asia & Pacific           3.85e8  3.41e8
##  3 Austria          High            Europe & Central Asia         1.97e8  1.88e8
##  4 Bangladesh       Lower Middle    South Asia                    2.95e8  2.95e8
##  5 Belgium          High            Europe & Central Asia         1.07e9  1.07e9
##  6 Brazil           Upper Middle    Latin America & Caribbean     5.54e7  5.25e7
##  7 Canada           High            North America                 4.70e8  4.51e8
##  8 Chile            High            Latin America & Caribbean     6.15e7  5.46e7
##  9 China            Upper Middle    East Asia & Pacific           2.06e8  1.30e8
## 10 Colombia         Upper Middle    Latin America & Caribbean     7.49e7  6.58e7
## # … with 46 more rows, and abbreviated variable names ¹​issued_amount_usd_mean,
## #   ²​amount_outstanding_usd_mean
## # ℹ Use `print(n = ...)` to see more rows
#generate ridgeline plot for income groups
ggplot(green_bond_country_features, aes(x = issued_amount_usd_mean, y = wb_income_group, fill = wb_income_group)) +
  geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
  labs(title = 'The distribution of issuance amount of green bonds for income groups') +
  theme_ridges() +
    theme(
      legend.position="none",
      panel.spacing = unit(0.1, "lines"),
      strip.text.x = element_text(size = 8)
    )
## Picking joint bandwidth of 71400000

#generate ridgeline plot for region groups

ggplot(green_bond_country_features, aes(x = issued_amount_usd_mean, y = wb_region, fill = wb_region)) +
  geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
  labs(title = 'The distribution of issuance amount of green bonds for region groups') +
  theme_ridges() +
    theme(
      legend.position="none",
      panel.spacing = unit(0.1, "lines"),
      strip.text.x = element_text(size = 8)
    )
## Picking joint bandwidth of 67500000

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.