Skip to content

Commit

Permalink
Add link to app to posts/international-external-debt-networks
Browse files Browse the repository at this point in the history
  • Loading branch information
christophscheuch committed Nov 30, 2024
1 parent 0acb1b5 commit 9e4a08f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ <h5 class="quarto-listing-category-title">Categories</h5><div class="quarto-list

<div class="quarto-listing quarto-listing-container-grid" id="listing-listing">
<div class="list grid quarto-listing-cols-3">
<div class="g-col-1" data-index="0" data-categories="R,Visualization" data-listing-date-sort="1732748400000" data-listing-file-modified-sort="1732973818815" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="5" data-listing-word-count-sort="931">
<div class="g-col-1" data-index="0" data-categories="R,Visualization" data-listing-date-sort="1732748400000" data-listing-file-modified-sort="1732982484291" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="5" data-listing-word-count-sort="975">
<a href="./posts/international-external-debt-network/index.html" class="quarto-grid-link">
<div class="quarto-grid-item card h-100 card-left">
<p class="card-img-top">
Expand Down
5 changes: 5 additions & 0 deletions docs/posts/international-external-debt-network/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ <h2 id="toc-title">On this page</h2>
<li><a href="#data-preparation" id="toc-data-preparation" class="nav-link active" data-scroll-target="#data-preparation">Data Preparation</a></li>
<li><a href="#debtor-centric-view" id="toc-debtor-centric-view" class="nav-link" data-scroll-target="#debtor-centric-view">Debtor-Centric View</a></li>
<li><a href="#creditor-centric-view" id="toc-creditor-centric-view" class="nav-link" data-scroll-target="#creditor-centric-view">Creditor-Centric View</a></li>
<li><a href="#putting-everyhing-into-an-app" id="toc-putting-everyhing-into-an-app" class="nav-link" data-scroll-target="#putting-everyhing-into-an-app">Putting Everyhing into an App</a></li>
<li><a href="#concluding-remarks" id="toc-concluding-remarks" class="nav-link" data-scroll-target="#concluding-remarks">Concluding Remarks</a></li>
</ul>
</nav>
Expand Down Expand Up @@ -433,6 +434,10 @@ <h2 class="anchored" data-anchor-id="creditor-centric-view">Creditor-Centric Vie
</div>
<p>This approach reveals which countries owe these creditors and in what amounts. For me, it is interesting to see that Austria shares a lof of counterparts with Germany (which is not surprising), but that Germany provides credit to many more counterparts around the World. Germany’s broader network of counterparts underscores its role as a significant lender globally, while Austria’s overlapping but smaller network highlights the nuanced dynamics of regional lending patterns.</p>
</section>
<section id="putting-everyhing-into-an-app" class="level2">
<h2 class="anchored" data-anchor-id="putting-everyhing-into-an-app">Putting Everyhing into an App</h2>
<p>Do you want to quickly look at different countries, counterparts, or time periods? The code above actually constitutes the buildings blocks of a shiny app that allows you to explore the data interactively - check out the <a href="https://apps.tidy-intelligence.com/apps/debt-network-visualizer/">Debt Network Visualizer</a>!</p>
</section>
<section id="concluding-remarks" class="level2">
<h2 class="anchored" data-anchor-id="concluding-remarks">Concluding Remarks</h2>
<p>By combining <code>wbids</code> for data retrieval, <code>tidyverse</code> for manipulation, and <code>visNetwork</code> for visualization, you can quickly uncover intricate patterns in global debt relationships. Try adapting this workflow to your own analysis!</p>
Expand Down
7 changes: 7 additions & 0 deletions docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -999,5 +999,12 @@
"title": "Global Debt Networks",
"section": "Debtor-Centric View",
"text": "Debtor-Centric View\nFor now, let’s narrow our focus to specific debtor countries. This step allows us to examine the relationships from a debtor’s perspective, understanding how much debt they owe and to whom. In the following, we focus on Nigeria and its neighbor Cameroon.\n\nselected_geographies &lt;- c(\"Nigeria\", \"Cameroon\")\n\nexternal_debt_sub &lt;- external_debt |&gt;\n filter(from %in% selected_geographies) \n\nvisNetwork requires two data frames: nodes and edges, each with corresponding properties. To enhance the visualization, we create helper functions for formatting node titles and labels:\n\nformat_title &lt;- function(id, value, type) {\n prefix &lt;- if_else(\n type == \"debtor\", \"&lt;br&gt;Received: \", \"&lt;br&gt;Provided: \"\n )\n debt &lt;- scales::label_number(\n accuracy = 0.1, scale_cut = scales::cut_short_scale()\n )(value)\n title &lt;- str_c(\n id, prefix, debt, \" USD\"\n )\n title\n}\n\nformat_label &lt;- function(id) {\n label &lt;- str_wrap(id, width = 20)\n label\n}\n\nWe now construct the nodes and edges for the network. Nodes represent entities (countries or institutions), and edges represent debt relationships. The data looks like this:\n\ncreate_nodes &lt;- function(external_debt_sub) {\n \n total_debt &lt;- sum(external_debt_sub$value)\n \n nodes &lt;- external_debt_sub |&gt; \n group_by(id = from, type = \"debtor\", color = \"Country\") |&gt; \n summarize(value = sum(value),\n .groups = \"drop\") |&gt; \n bind_rows(\n external_debt_sub |&gt; \n group_by(id = to, type = \"creditor\", color = counterpart_type) |&gt; \n summarize(value = sum(value),\n .groups = \"drop\")\n ) |&gt; \n mutate(\n title = format_title(id, value, type),\n label = format_label(id),\n size = value / total_debt,\n color = case_when(\n color == \"Other\" ~ \"#C46231\",\n color == \"Country\" ~ \"#3193C4\",\n color == \"Global MDBs\" ~ \"#AB31C4\",\n color == \"Bondholders\" ~ \"#4AC431\"\n )\n )\n nodes\n}\n\nnodes &lt;- create_nodes(external_debt_sub)\nnodes\n\n# A tibble: 33 × 7\n id type color value title label size\n &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt; &lt;dbl&gt;\n 1 Cameroon debt… #319… 1.18e10 Came… \"Cam… 2.28e-1\n 2 Nigeria debt… #319… 4.00e10 Nige… \"Nig… 7.72e-1\n 3 African Dev. Bank cred… #C46… 4.18e 9 Afri… \"Afr… 8.07e-2\n 4 African Export-Import Bank cred… #C46… 7.60e 7 Afri… \"Afr… 1.47e-3\n 5 Arab Bank for Economic Dev. in Afric… cred… #C46… 7.23e 7 Arab… \"Ara… 1.39e-3\n 6 Austria cred… #319… 8.78e 6 Aust… \"Aus… 1.69e-4\n 7 Belgium cred… #319… 5.69e 7 Belg… \"Bel… 1.10e-3\n 8 Bondholders cred… #4AC… 1.73e10 Bond… \"Bon… 3.33e-1\n 9 Central Bank of West African States … cred… #C46… 2.28e 7 Cent… \"Cen… 4.40e-4\n10 China cred… #319… 8.08e 9 Chin… \"Chi… 1.56e-1\n# ℹ 23 more rows\n\n\nEdges add the connective tissue to the network, showing who owes whom. Here is how the example data looks like:\n\ncreate_edges &lt;- function(external_debt_sub) {\n edges &lt;- external_debt_sub |&gt; \n select(from, to) |&gt; \n mutate(\n shadow = TRUE, \n color = \"grey\",\n smooth = TRUE\n )\n edges\n}\n\nedges &lt;- create_edges(external_debt_sub)\nedges\n\n# A tibble: 45 × 5\n from to shadow color smooth\n &lt;chr&gt; &lt;chr&gt; &lt;lgl&gt; &lt;chr&gt; &lt;lgl&gt; \n 1 Cameroon World Bank-IDA TRUE grey TRUE \n 2 Cameroon World Bank-IBRD TRUE grey TRUE \n 3 Cameroon United States TRUE grey TRUE \n 4 Cameroon United Kingdom TRUE grey TRUE \n 5 Cameroon United Arab Emirates TRUE grey TRUE \n 6 Cameroon Turkiye TRUE grey TRUE \n 7 Cameroon Switzerland TRUE grey TRUE \n 8 Cameroon Spain TRUE grey TRUE \n 9 Cameroon Saudi Arabia TRUE grey TRUE \n10 Cameroon OPEC Fund for International Dev. TRUE grey TRUE \n# ℹ 35 more rows\n\n\nThe visNetwork library brings everything together, producing an interactive network. This visualization provides a debtor-centric perspective, illustrating how selected countries distribute their debt obligations among creditors.\n\nvisualize_network &lt;- function(external_debt_sub) {\n nodes &lt;- create_nodes(external_debt_sub)\n edges &lt;- create_edges(external_debt_sub)\n \n visNetwork(\n nodes, edges, width = \"100%\", height = \"600px\"\n ) |&gt; \n visNodes(shape = \"dot\")\n}\n\nvisualize_network(external_debt_sub)\n\n\n\n\n\nVisualizing the network from a debtor’s perspective sheds light on the diversity of funding sources for countries like Nigeria and Cameroon. While both nations share some creditors, the wider spread of Cameroon’s creditor network could indicate stronger diversification in funding sources—a potentially advantageous position for economic resilience."
},
{
"objectID": "posts/international-external-debt-network/index.html#putting-everyhing-into-an-app",
"href": "posts/international-external-debt-network/index.html#putting-everyhing-into-an-app",
"title": "Global Debt Networks",
"section": "Putting Everyhing into an App",
"text": "Putting Everyhing into an App\nDo you want to quickly look at different countries, counterparts, or time periods? The code above actually constitutes the buildings blocks of a shiny app that allows you to explore the data interactively - check out the Debt Network Visualizer!"
}
]
2 changes: 1 addition & 1 deletion docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</url>
<url>
<loc>https://blog.tidy-intelligence.com/posts/international-external-debt-network/index.html</loc>
<lastmod>2024-11-30T13:36:58.815Z</lastmod>
<lastmod>2024-11-30T16:01:24.291Z</lastmod>
</url>
<url>
<loc>https://blog.tidy-intelligence.com/posts/dplyr-vs-tidierdata/index.html</loc>
Expand Down
4 changes: 4 additions & 0 deletions posts/international-external-debt-network/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ visualize_network(external_debt_sub)

This approach reveals which countries owe these creditors and in what amounts. For me, it is interesting to see that Austria shares a lof of counterparts with Germany (which is not surprising), but that Germany provides credit to many more counterparts around the World. Germany’s broader network of counterparts underscores its role as a significant lender globally, while Austria’s overlapping but smaller network highlights the nuanced dynamics of regional lending patterns.

## Putting Everyhing into an App

Do you want to quickly look at different countries, counterparts, or time periods? The code above actually constitutes the buildings blocks of a shiny app that allows you to explore the data interactively - check out the [Debt Network Visualizer](https://apps.tidy-intelligence.com/apps/debt-network-visualizer/)!

## Concluding Remarks

By combining `wbids` for data retrieval, `tidyverse` for manipulation, and `visNetwork` for visualization, you can quickly uncover intricate patterns in global debt relationships. Try adapting this workflow to your own analysis!

0 comments on commit 9e4a08f

Please sign in to comment.