From aa0c95ad257da80a6a21ae9fe4d25e29ae12d07f Mon Sep 17 00:00:00 2001 From: jacobvjk Date: Mon, 6 Jan 2025 11:38:18 +0100 Subject: [PATCH] clearer names for sankey columns --- R/plot_sankey.R | 8 +++++--- R/prep_sankey.R | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/R/plot_sankey.R b/R/plot_sankey.R index 5d2d9c0..bdc0244 100644 --- a/R/plot_sankey.R +++ b/R/plot_sankey.R @@ -22,7 +22,7 @@ #' @noRd plot_sankey <- function(data, - y_axis, + y_axis = "loan_size_outstanding", initial_node, middle_node = "sector", end_node = "is_aligned", @@ -40,12 +40,14 @@ plot_sankey <- function(data, axis1 = .data[["initial_node"]], axis2 = .data[["middle_node"]], axis3 = .data[["end_node"]], - y = .data[["y_axis"]] + # y = .data[["y_axis"]] + y = .data[["loan_size_outstanding"]] ) ) + ggplot2::scale_y_continuous(labels = scales::comma) + ggplot2::ylab(glue::glue("Financial exposure (in {currency})")) + - ggalluvial::geom_alluvium(ggplot2::aes(fill = .data[["stratum"]])) + + ggalluvial::geom_alluvium(ggplot2::aes(fill = .data[["is_aligned"]])) + + # ggalluvial::geom_alluvium(ggplot2::aes(fill = .data[["stratum"]])) + ggplot2::scale_fill_manual( values = c("Aligned" = "green4", "Not aligned" = "red3", "Unknown" = "gray30") ) + diff --git a/R/prep_sankey.R b/R/prep_sankey.R index 76a37af..534fa2c 100644 --- a/R/prep_sankey.R +++ b/R/prep_sankey.R @@ -71,19 +71,21 @@ prep_sankey <- function(data_alignment, ) %>% dplyr::arrange(!!rlang::sym(group_var), .data[["is_aligned"]]) %>% dplyr::mutate( - y_axis = .data$loan_size_outstanding, + # y_axis = .data$loan_size_outstanding, initial_node = .data[[group_var]], - end_node = .data$is_aligned, - stratum = .data$is_aligned + end_node = .data$is_aligned#, + # stratum = .data$is_aligned ) %>% dplyr::select( dplyr::all_of( c( - "y_axis", + "loan_size_outstanding", + # "y_axis", "initial_node", "middle_node", "end_node", - "stratum", + "is_aligned", + # "stratum", currency = "loan_size_outstanding_currency" ) )