Skipping install of 'countrycode' from a github remote, the SHA1 (ef867ffb) has not changed since last install.
Use `force = TRUE` to force installation
── 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
library(janitor)
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
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.
# we want to compare these two indicatorsindicators_we_want <-c("Green Bond Issuances by Country", "Sovereign Green Bond Issuances")green_debt_subset <- green_debt |># from the janitor package -- makes variables snake_case so they are easier to work withclean_names() |># filter for the vector of indicators we defined abovefilter(indicator %in% indicators_we_want) |># "f\\d{4}" is a regular expression (regex) that searches for all columns that are f + four digits.# Ask ChatGPT to explain this to you.select(country, iso3, indicator, matches("f\\d{4}"))
Problem 1
Step 1: Use the countrycode package to add the region as a variable to green_debt_subset.
Step 2: Calculate the cumulative issuance of green bonds by region.
Step 3: Use ggplot2 to make a data visualization comparing regional cumulative issuance.
Step 4: Make your plot look professionally presentable, as we did above.
Step 2: Use clean_names() to make the variable names snake_case
Step 3: Filter out observations where type_of_issuer is “Not Applicable”
Step 4: Use the tools taught in this chapter to provide a compelling data visualization and some repeatable factoids that provide actionable insights about green bond issuers.
green_debt_with_issuer <- green_debt |># from the janitor package -- makes variables snake_case so they are easier to work withclean_names() |># filter out observations where type_of_issuer is “Not Applicable”filter(!type_of_issuer =="Not Applicable")green_debt_with_issuer_tidy <- green_debt_with_issuer |>pivot_longer(cols =matches("f\\d{4}"),names_to ="year",values_to ="issuance_bn_usd",names_transform = readr::parse_number,values_drop_na =TRUE )green_debt_with_issuer_cumulative <- green_debt_with_issuer_tidy |>group_by(type_of_issuer) |>mutate(green_debt_issuer_cumulative =sum(issuance_bn_usd))ggplot(green_debt_with_issuer_cumulative, aes(x = green_debt_issuer_cumulative,y = type_of_issuer,fill = type_of_issuer)) +geom_bar(stat ="identity") +theme_minimal() +scale_x_continuous(labels = scales::label_dollar(suffix =" bn"),expand =c(0,0)) +labs(title ="Cumulative Green Debt Issuance by Issuer",subtitle ="Nonfinancial corporations and banks are the main issuers of green debt",x ="Cumulative Issuance (USD)",y ="Issuer",caption ="Boyuan Gao")
Problem 3
Repeat the process from problem 2 for use_of_proceed and for principal_currency
What are green bond proceeds used for?
green_debt_with_use_of_proceed <- green_debt |># from the janitor package -- makes variables snake_case so they are easier to work withclean_names() |># filter out observations where type_of_issuer is “Not Applicable”filter(!use_of_proceed =="Not Applicable")green_debt_with_use_of_proceed |>distinct(use_of_proceed)
# A tibble: 69 × 1
use_of_proceed
<chr>
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
# ℹ 59 more rows
What do we know about the currency of issuance? Is that changing over time?
green_debt_with_currency_of_issuance <- green_debt |># from the janitor package -- makes variables snake_case so they are easier to work withclean_names() |># filter out observations where type_of_issuer is “Not Applicable”filter(!principal_currency =="Not Applicable")green_debt_with_currency_of_issuance_tidy <- green_debt_with_currency_of_issuance |>pivot_longer(cols =matches("f\\d{4}"),names_to ="year",values_to ="issuance_bn_usd",names_transform = readr::parse_number, )cumulative_issuance_by_currency <- green_debt_with_currency_of_issuance_tidy |>arrange(principal_currency, year) |>group_by(principal_currency, year) |>mutate(cumulative_bn_usd =cumsum(issuance_bn_usd)) |>filter(!is.na(cumulative_bn_usd))biggest_green_bond_currency <- cumulative_issuance_by_currency |>group_by(principal_currency) |>slice_max(order_by = year) |>arrange(cumulative_bn_usd|>desc()) |>select(principal_currency, cumulative_bn_usd) |>ungroup()top_10_chart <- biggest_green_bond_currency |># take the top 10, ordered by cumulative issuanceslice_max(order_by = cumulative_bn_usd, n =10) |>ggplot(aes(x = cumulative_bn_usd, # order countries by cumulative issuancey =fct_reorder(.f = principal_currency, .x = cumulative_bn_usd,),fill = principal_currency )) +geom_col() top_10_chart +theme_minimal() +scale_x_continuous(labels = scales::label_dollar(suffix =" bn"),expand =c(0,0)) +labs(title ="Top 10 Green Bond Currencies",subtitle ="Euro takes the lead, followed by US Dollar and Chinese Yuan",x ="Cumulative Issuance (USD)",y ="Currency",caption ="Boyuan Gao")