Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(plot_emission_intensity)
export(plot_match_success_rate)
export(plot_techmix)
export(plot_trajectory)
export(prep_emission_intensity)
Expand All @@ -22,6 +23,7 @@ export(spell_out_technology)
export(theme_2dii)
export(to_title)
import(ggplot2)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,arrange)
Expand Down
47 changes: 47 additions & 0 deletions R/plot_match_success_rate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Title
#'
#' @param .data A data frame like the outputs of
#' `r2dii.match::calculate_match_success_rate()`.
#' @param ... Additional grouping columns.
#' @param .x The name of the column to be used as the x-axis.
#'
#' @returns An object of class "ggplot".
#'
#' @export
#'
#' @examples
#' coverage <-
#' r2dii.data::loanbook_demo %>%
#' r2dii.match::match_name(r2dii.data::abcd_demo) %>%
#' r2dii.match::prioritize() %>%
#' r2dii.match::calculate_match_success_rate(loanbook = r2dii.data::loanbook_demo)
#'
#' plot_match_success_rate(coverage)
#'
#' @importFrom dplyr %>%

plot_match_success_rate <- function(.data, ..., .x = NULL) {
if (is.null(.x)) {
.x <- as.symbol("matched")
} else {
.x <- as.symbol(.x)
}

.data %>%
dplyr::summarize(
loan_size_outstanding = sum(.data$loan_size_outstanding, na.rm = TRUE),
.by = c("matched", ...)
) %>%
dplyr::arrange(.data[["matched"]], ...) %>%
ggplot2::ggplot() +
ggplot2::geom_col(
mapping = ggplot2::aes(
x = {{.x}},
y = .data[["loan_size_outstanding"]],
fill = .data[["matched"]]
)
) +
theme_2dii() +
scale_fill_r2dii() +
ggplot2::theme(legend.position = "top")
}
32 changes: 32 additions & 0 deletions man/plot_match_success_rate.Rd

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