Skip to content

Commit

Permalink
clearer names for sankey columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobvjk committed Jan 6, 2025
1 parent d8091ef commit aa0c95a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions R/plot_sankey.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
) +
Expand Down
12 changes: 7 additions & 5 deletions R/prep_sankey.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
Expand Down

0 comments on commit aa0c95a

Please sign in to comment.