Skip to content

Commit

Permalink
Modify the colors to match the risk categories (#31)
Browse files Browse the repository at this point in the history
* changed color scaled to corresponds to the risk categories values

* used fill_scale_color function

* used swith mode function for consistency

* changed plot sankey
  • Loading branch information
lindadelacombaz authored Aug 1, 2023
1 parent b215e02 commit 173964b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions R/plot_sankey.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,31 @@ plot_sankey <- function(data, with_company = TRUE, mode = c("equal_weight", "wor
"worst_case_finance",
"best_case_finance"
)
data |> check_crucial_names(c(names(select(data, matches(crucial)))))
risk_category_var <- names(select(data, matches("_risk_category")))
data |> check_crucial_names(names_matching(data, crucial))
risk_var <- names_matching(data, "_risk_category")

limits <- c("Bank", if (with_company) "Company", NULL, "Tilt Sector", risk_category_var)
limits <- c("Bank", if (with_company) "Company", NULL, "Tilt Sector", risk_var)

# TODO : color code per low, medium and high
p <- ggplot(
data = data,
aes(
y = .data[[switch_mode(mode)]],
axis1 = .data$kg_id,
axis3 = .data$tilt_sector,
axis4 = factor(.data[[risk_category_var]], levels = c("low", "medium", "high"))
axis4 = as_risk_category(.data[[risk_var]]),
fill = as_risk_category(.data[[risk_var]])
)
) +
scale_x_discrete(
limits = limits,
expand = c(.2, .05)
) +
geom_alluvium(aes(
fill = case_when(
mode == "equal_weight" ~ .data$equal_weight_finance,
mode == "worst_case" ~ .data$worst_case_finance,
mode == "best_case" ~ .data$best_case_finance,
mode == "main_activity" ~ .data$main_activity
)
)) +
geom_alluvium() +
geom_stratum() +
geom_text(stat = StatStratum, aes(label = after_stat(.data$stratum))) +
fill_score_colors() +
theme_minimal() +
labs(fill = "amount") +
labs(fill = "Risk Categories") +
ggtitle(
"Sankey Plot",
paste("Stratified by the amount of loan by the bank and", mode, "mode")
Expand Down
Binary file modified man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/plot_xctr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 173964b

Please sign in to comment.