Skip to contents

Generates faceted ggplot displaying the distribution of either selected metric(s) or all the set of diagnostic indices. By default, distribution(s) are ungrouped; if a group_var is specified, distributions are grouped by its levels within each panel. If only one metric is specified in metric_var, a single panel is displayed.

Usage

plot_metric_distribution(
  metric_summary,
  colour_var,
  metric_var = NULL,
  group_var = NULL
)

Arguments

metric_summary

A data frame containing computed diagnostic metrics and the pre-defined grouping information, generated by passing the output of any diagnostic metrics function to add_group_info

colour_var

A variable in metric_summary data frame whose levels are mapped to distinct colours in the resulting plot

metric_var

Character string or vector of character strings specifying metric variable name(s) in metric_summary to plot If NULL (default), distributions are plotted for all metric variables in metric_summary Is specified, only the distribution for the specified metric(s) will be plotted

group_var

A grouping variable in the WDI data set (e.g., "region" or "income") Default to NULL If NULL, distributions are ungrouped and if specified, distributions are grouped by the levels of the variable

Value

A ggplot object displaying either the ungrouped or grouped distribution of metric(s) in metric_summary. Each metric is displayed in a separate facet panel; if one metric is specified, a single panel is shown.

Examples

pm_diagnostic_metrics <- compute_diagnostic_indices(pm_data, group_var = "region")
pm_diagnostic_metrics_group <- add_group_info(metric_summary = pm_diagnostic_metrics,pm_data)
plot_metric_distribution(pm_diagnostic_metrics_group, colour_var = "region", group_var = "region")