diff --git a/_freeze/posts/international-external-debt-network/index/execute-results/html.json b/_freeze/posts/international-external-debt-network/index/execute-results/html.json index 4aa8466..3d3fff5 100644 --- a/_freeze/posts/international-external-debt-network/index/execute-results/html.json +++ b/_freeze/posts/international-external-debt-network/index/execute-results/html.json @@ -1,8 +1,8 @@ { - "hash": "487e9706b4e4db5c1cf2a58921ccecf5", + "hash": "31109279e85b41b7f4ad8d03788e57ae", "result": { "engine": "knitr", - "markdown": "---\ntitle: \"Global Debt Networks\"\ndescription: \"Explore external debt relationships with interactive networks in R\"\nmetadata:\n pagetitle: \"International External Debt Network\"\nauthor: \"Christoph Scheuch\"\ndate: \"2024-11-28\" \nimage: thumbnail.png\nimage-alt: A whimsical and friendly spider with expressive eyes sits on a desk in a bright and inviting office. The spider is focused on a computer screen displaying a colorful network visualization. Sunlight streams through large windows, casting a warm glow over the room. The office is decorated with vibrant green plants in terracotta pots, neatly arranged colorful books on shelves, and cozy furnishings, creating a lively and welcoming atmosphere. Created with DALL-E.\ncategories: \n - R\n - Visualization\nformat:\n html: \n fig-width: 12\n fig-height: 8\n fig-dpi: 300\n---\n\n\n\nIn this blog post, I visualize external debt using interactive networks with R. Understanding external debt flows between countries and creditors is a crucial aspect in analyzing global economic relationships. Using tools such as the recently released [`wbids`](https://teal-insights.github.io/r-wbids/) package to download data from the World Bank International Debt statistics and [`visNetwork`](https://cran.r-project.org/web/packages/visNetwork/vignettes/Introduction-to-visNetwork.html) for visualization, we can uncover interesting insights. \n\nThis post relies on the following packages.\n\n::: callout-note\nDue to a bug in `scales::cut_short_scale()`, I installed the development version of `scales` from [GitHub](https://github.com/r-lib/scales).\n:::\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\nlibrary(wbids)\nlibrary(visNetwork)\nlibrary(scales)\n```\n:::\n\n\n\n## Data Preparation\n\nThe `wbids` package provides easy access to download debtor-creditor relationships for all available countries. Here, we pull external debt data (IDS series \"DT.DOD.DPPG.CD\") for 2022 using `ids_get()` and enrich it with geographical and counterpart details. Note that we drop \"World\" and \"Region\" counterparts because we rather want to look at their individual components.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ngeographies <- ids_list_geographies() |> \n filter(geography_type != \"Region\")\n\nexternal_debt_raw <- geographies$geography_id |> \n map_df(\\(x) ids_get(x, \"DT.DOD.DPPG.CD\", \"all\", 2022, 2022))\n\ncounterparts <- ids_list_counterparts()\n\nexternal_debt <- external_debt_raw |> \n filter(value > 0) |> \n left_join(geographies, join_by(geography_id)) |> \n left_join(counterparts, join_by(counterpart_id)) |> \n filter(!counterpart_name %in% c(\"World\", \"Region\")) |> \n select(from = geography_name, to = counterpart_name, value, counterpart_type) |> \n mutate(to = str_squish(to))\n```\n:::\n\n\n\n## Debtor-Centric View\n\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\n\n\n::: {.cell}\n\n```{.r .cell-code}\nselected_geographies <- c(\"Nigeria\", \"Cameroon\")\n\nexternal_debt_sub <- external_debt |>\n filter(from %in% selected_geographies) \n```\n:::\n\n\n\n`visNetwork` 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\n\n\n::: {.cell}\n\n```{.r .cell-code}\nformat_title <- function(id, value, type) {\n prefix <- if_else(\n type == \"debtor\", \"
Received: \", \"
Provided: \"\n )\n debt <- scales::label_number(\n accuracy = 0.1, scale_cut = scales::cut_short_scale()\n )(value)\n title <- str_c(\n id, prefix, debt, \" USD\"\n )\n title\n}\n\nformat_label <- function(id) {\n label <- str_wrap(id, width = 20)\n label\n}\n```\n:::\n\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\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncreate_nodes <- function(external_debt_sub) {\n \n total_debt <- sum(external_debt_sub$value)\n \n nodes <- external_debt_sub |> \n group_by(id = from, type = \"debtor\", color = \"Country\") |> \n summarize(value = sum(value),\n .groups = \"drop\") |> \n bind_rows(\n external_debt_sub |> \n group_by(id = to, type = \"creditor\", color = counterpart_type) |> \n summarize(value = sum(value),\n .groups = \"drop\")\n ) |> \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 <- create_nodes(external_debt_sub)\nnodes\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 33 × 7\n id type color value title label size\n \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\n\n:::\n:::\n\n\n\nEdges add the connective tissue to the network, showing who owes whom. Here is how the example data looks like:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncreate_edges <- function(external_debt_sub) {\n edges <- external_debt_sub |> \n select(from, to) |> \n mutate(\n shadow = TRUE, \n color = \"grey\",\n smooth = TRUE\n )\n edges\n}\n\nedges <- create_edges(external_debt_sub)\nedges\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 45 × 5\n from to shadow color smooth\n \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\n\n:::\n:::\n\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\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvisualize_network <- function(external_debt_sub) {\n nodes <- create_nodes(external_debt_sub)\n edges <- create_edges(external_debt_sub)\n \n visNetwork(\n nodes, edges, width = \"100%\", height = \"600px\"\n ) |> \n visNodes(shape = \"dot\")\n}\n\nvisualize_network(external_debt_sub)\n```\n\n::: {.cell-output-display}\n\n```{=html}\n
\n\n```\n\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.\n\n## Creditor-Centric View\n\nIf you wondered why we wrapped everything into functions, then here is the resolution: we can use the same function to examine the network from creditors' perspective. For example, let's focus on Austria (my home country) and Germany (where I currently live).\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nselected_counterparts <- c(\"Austria\", \"Germany, Fed. Rep. of\")\n\nexternal_debt_sub <- external_debt |>\n filter(to %in% selected_counterparts) \n\nvisualize_network(external_debt_sub)\n```\n\n::: {.cell-output-display}\n\n```{=html}\n
\n\n```\n\n:::\n:::\n\n\n\nThis 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. \n\n## Concluding Remarks\n\nBy 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!\n", + "markdown": "---\ntitle: \"Global Debt Networks\"\ndescription: \"Explore external debt relationships with interactive networks in R\"\nmetadata:\n pagetitle: \"International External Debt Network\"\nauthor: \"Christoph Scheuch\"\ndate: \"2024-11-28\" \nimage: thumbnail.png\nimage-alt: A whimsical and friendly spider with expressive eyes sits on a desk in a bright and inviting office. The spider is focused on a computer screen displaying a colorful network visualization. Sunlight streams through large windows, casting a warm glow over the room. The office is decorated with vibrant green plants in terracotta pots, neatly arranged colorful books on shelves, and cozy furnishings, creating a lively and welcoming atmosphere. Created with DALL-E.\ncategories: \n - R\n - Visualization\nformat:\n html: \n fig-width: 12\n fig-height: 8\n fig-dpi: 300\n---\n\n\n\nIn this blog post, I visualize external debt using interactive networks with R. Understanding external debt flows between countries and creditors is a crucial aspect in analyzing global economic relationships. Using tools such as the recently released [`wbids`](https://teal-insights.github.io/r-wbids/) package to download data from the World Bank International Debt statistics and [`visNetwork`](https://cran.r-project.org/web/packages/visNetwork/vignettes/Introduction-to-visNetwork.html) for visualization, we can uncover interesting insights. \n\nThis post relies on the following packages.\n\n::: callout-note\nDue to a bug in `scales::cut_short_scale()`, I installed the development version of `scales` from [GitHub](https://github.com/r-lib/scales).\n:::\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\nlibrary(wbids)\nlibrary(visNetwork)\nlibrary(scales)\n```\n:::\n\n\n\n## Data Preparation\n\nThe `wbids` package provides easy access to download debtor-creditor relationships for all available countries. Here, we pull external debt data (IDS series \"DT.DOD.DPPG.CD\") for 2022 using `ids_get()` and enrich it with geographical and counterpart details. Note that we drop \"World\" and \"Region\" counterparts because we rather want to look at their individual components.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ngeographies <- ids_list_geographies() |> \n filter(geography_type != \"Region\")\n\nexternal_debt_raw <- geographies$geography_id |> \n map_df(\\(x) ids_get(x, \"DT.DOD.DPPG.CD\", \"all\", 2022, 2022))\n\ncounterparts <- ids_list_counterparts()\n\nexternal_debt <- external_debt_raw |> \n filter(value > 0) |> \n left_join(geographies, join_by(geography_id)) |> \n left_join(counterparts, join_by(counterpart_id)) |> \n filter(!counterpart_name %in% c(\"World\", \"Region\")) |> \n select(from = geography_name, to = counterpart_name, value, counterpart_type) |> \n mutate(to = str_squish(to))\n```\n:::\n\n\n\n## Debtor-Centric View\n\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\n\n\n::: {.cell}\n\n```{.r .cell-code}\nselected_geographies <- c(\"Nigeria\", \"Cameroon\")\n\nexternal_debt_sub <- external_debt |>\n filter(from %in% selected_geographies) \n```\n:::\n\n\n\n`visNetwork` 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\n\n\n::: {.cell}\n\n```{.r .cell-code}\nformat_title <- function(id, value, type) {\n prefix <- if_else(\n type == \"debtor\", \"
Received: \", \"
Provided: \"\n )\n debt <- scales::label_number(\n accuracy = 0.1, scale_cut = scales::cut_short_scale()\n )(value)\n title <- str_c(\n id, prefix, debt, \" USD\"\n )\n title\n}\n\nformat_label <- function(id) {\n label <- str_wrap(id, width = 20)\n label\n}\n```\n:::\n\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\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncreate_nodes <- function(external_debt_sub) {\n \n total_debt <- sum(external_debt_sub$value)\n \n nodes <- external_debt_sub |> \n group_by(id = from, type = \"debtor\", color = \"Country\") |> \n summarize(value = sum(value),\n .groups = \"drop\") |> \n bind_rows(\n external_debt_sub |> \n group_by(id = to, type = \"creditor\", color = counterpart_type) |> \n summarize(value = sum(value),\n .groups = \"drop\")\n ) |> \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 <- create_nodes(external_debt_sub)\nnodes\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 33 × 7\n id type color value title label size\n \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\n\n:::\n:::\n\n\n\nEdges add the connective tissue to the network, showing who owes whom. Here is how the example data looks like:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncreate_edges <- function(external_debt_sub) {\n edges <- external_debt_sub |> \n select(from, to) |> \n mutate(\n shadow = TRUE, \n color = \"grey\",\n smooth = TRUE\n )\n edges\n}\n\nedges <- create_edges(external_debt_sub)\nedges\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 45 × 5\n from to shadow color smooth\n \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\n\n:::\n:::\n\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\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvisualize_network <- function(external_debt_sub) {\n nodes <- create_nodes(external_debt_sub)\n edges <- create_edges(external_debt_sub)\n \n visNetwork(\n nodes, edges, width = \"100%\", height = \"600px\"\n ) |> \n visNodes(shape = \"dot\")\n}\n\nvisualize_network(external_debt_sub)\n```\n\n::: {.cell-output-display}\n\n```{=html}\n
\n\n```\n\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.\n\n## Creditor-Centric View\n\nIf you wondered why we wrapped everything into functions, then here is the resolution: we can use the same function to examine the network from creditors' perspective. For example, let's focus on Austria (my home country) and Germany (where I currently live).\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nselected_counterparts <- c(\"Austria\", \"Germany, Fed. Rep. of\")\n\nexternal_debt_sub <- external_debt |>\n filter(to %in% selected_counterparts) \n\nvisualize_network(external_debt_sub)\n```\n\n::: {.cell-output-display}\n\n```{=html}\n
\n\n```\n\n:::\n:::\n\n\n\nThis 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. \n\n## Putting Everyhing into an App\n\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](https://apps.tidy-intelligence.com/apps/debt-network-visualizer/)!\n\n## Concluding Remarks\n\nBy 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!\n", "supporting": [], "filters": [ "rmarkdown/pagebreak.lua" diff --git a/docs/index.html b/docs/index.html index f17ad02..509e31e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -221,7 +221,7 @@
Categories
-
+

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!

+

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!

diff --git a/docs/search.json b/docs/search.json index 141e57f..93dc21a 100644 --- a/docs/search.json +++ b/docs/search.json @@ -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 <- c(\"Nigeria\", \"Cameroon\")\n\nexternal_debt_sub <- external_debt |>\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 <- function(id, value, type) {\n prefix <- if_else(\n type == \"debtor\", \"<br>Received: \", \"<br>Provided: \"\n )\n debt <- scales::label_number(\n accuracy = 0.1, scale_cut = scales::cut_short_scale()\n )(value)\n title <- str_c(\n id, prefix, debt, \" USD\"\n )\n title\n}\n\nformat_label <- function(id) {\n label <- 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 <- function(external_debt_sub) {\n \n total_debt <- sum(external_debt_sub$value)\n \n nodes <- external_debt_sub |> \n group_by(id = from, type = \"debtor\", color = \"Country\") |> \n summarize(value = sum(value),\n .groups = \"drop\") |> \n bind_rows(\n external_debt_sub |> \n group_by(id = to, type = \"creditor\", color = counterpart_type) |> \n summarize(value = sum(value),\n .groups = \"drop\")\n ) |> \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 <- create_nodes(external_debt_sub)\nnodes\n\n# A tibble: 33 × 7\n id type color value title label size\n <chr> <chr> <chr> <dbl> <chr> <chr> <dbl>\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 <- function(external_debt_sub) {\n edges <- external_debt_sub |> \n select(from, to) |> \n mutate(\n shadow = TRUE, \n color = \"grey\",\n smooth = TRUE\n )\n edges\n}\n\nedges <- create_edges(external_debt_sub)\nedges\n\n# A tibble: 45 × 5\n from to shadow color smooth\n <chr> <chr> <lgl> <chr> <lgl> \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 <- function(external_debt_sub) {\n nodes <- create_nodes(external_debt_sub)\n edges <- create_edges(external_debt_sub)\n \n visNetwork(\n nodes, edges, width = \"100%\", height = \"600px\"\n ) |> \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!" } ] \ No newline at end of file diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 943a93e..a12216e 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -6,7 +6,7 @@ https://blog.tidy-intelligence.com/posts/international-external-debt-network/index.html - 2024-11-30T13:36:58.815Z + 2024-11-30T16:01:24.291Z https://blog.tidy-intelligence.com/posts/dplyr-vs-tidierdata/index.html diff --git a/posts/international-external-debt-network/index.qmd b/posts/international-external-debt-network/index.qmd index ccae4c1..62b01cf 100644 --- a/posts/international-external-debt-network/index.qmd +++ b/posts/international-external-debt-network/index.qmd @@ -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!