Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #89 from RMI-PACTA/88-rm-alignment-by-exposure-plot
Browse files Browse the repository at this point in the history
rm plot that was extracted to package
  • Loading branch information
jacobvjk authored Mar 13, 2024
2 parents c90785e + 554c901 commit 121744c
Showing 1 changed file with 0 additions and 103 deletions.
103 changes: 0 additions & 103 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -357,109 +357,6 @@ validate_input_data_generate_individual_outputs <- function(data,
invisible()
}

# scatter plot net alignment by financial exposure----
prep_scatter_alignment_exposure <- function(data,
year,
region,
scenario,
category,
exclude_group_ids = "benchmark") {
data <- data %>%
dplyr::filter(
!grepl(paste0(.env$exclude_group_ids, collapse = "|"), .data$group_id)
) %>%
dplyr::filter(
.data$year == .env$year,
.data$region == .env$region,
.data$scenario == .env$scenario
) %>%
dplyr::select(
dplyr::all_of(
c(
.env$category,
"scenario",
"region",
"sector",
"year",
"exposure_weighted_net_alignment",
"sum_loan_size_outstanding"
)
)
)

data
}

plot_scatter_alignment_exposure <- function(data,
floor_outliers,
cap_outliers,
category,
currency) {

if (!is.null(floor_outliers)) {
data <- data %>%
mutate(
exposure_weighted_net_alignment = if_else(
.data$exposure_weighted_net_alignment <= .env$floor_outliers,
.env$floor_outliers,
.data$exposure_weighted_net_alignment
)
)
}

if (!is.null(cap_outliers)) {
data <- data %>%
mutate(
exposure_weighted_net_alignment = if_else(
.data$exposure_weighted_net_alignment >= .env$cap_outliers,
.env$cap_outliers,
.data$exposure_weighted_net_alignment
)
)
}

title <- glue::glue("Net Aggregate Alignment By Financial Exposure And Sector")
subtitle <- ""
if (any(!is.null(floor_outliers), !is.null(cap_outliers))) {
subtitle <- glue::glue(
"{subtitle}Outliers are displayed on the lower and upper boundaries: {floor_outliers} and {cap_outliers}.",
.trim = FALSE
)
}

plot <- data %>%
dplyr::mutate(sector = tools::toTitleCase(.data$sector)) %>%
ggplot2::ggplot(
ggplot2::aes(
x = sum_loan_size_outstanding,
y = exposure_weighted_net_alignment,
color = !!rlang::sym(category)
)
) +
ggplot2::geom_point() +
ggplot2::geom_hline(yintercept = 0) +
ggplot2::ylim(-1, 1) +
ggplot2::scale_x_continuous(labels = scales::comma) +
ggplot2::facet_wrap(
~ sector
) +
ggplot2::labs(
title = title,
subtitle = subtitle,
color = r2dii.plot::to_title(category)
) +
ggplot2::xlab(glue::glue("Financial Exposure (in {currency})")) +
ggplot2::ylab("Net Aggregate Alignment") +
r2dii.plot::scale_colour_r2dii() +
ggplot2::theme_bw() +
ggplot2::theme(
axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust=1),
panel.grid = ggplot2::element_blank()
)

plot
}

# plot match success rate----
plot_match_success_rate <- function(data,
aggregate,
Expand Down

0 comments on commit 121744c

Please sign in to comment.