| Title: | Risk and Gap Analysis for the CGIAR Research Investment Opportunities Report |
|---|---|
| Description: | Reads IMPACT model scenario results (via GFSir) and builds the risk and gap analysis used in the Research Investment Opportunities (RIO) report: hunger, diet, nutrient adequacy and blue water indicators against targets; pathway analysis across socioeconomic and climate scenarios; maps, target trajectories and comparisons of Breeding For Tomorrow (B4T) scenarios against the baseline. |
| Authors: | Abhijeet Mishra [aut, cre] (ORCID: <https://orcid.org/0000-0002-8287-9922>), Claude [aut] (AI coding assistant (Anthropic)) |
| Maintainer: | Abhijeet Mishra <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.1.0 |
| Built: | 2026-10-09 02:23:35 UTC |
| Source: | https://github.com/IFPRI/CRIO |
GFSir parses the 4th id segment into co2, so B4T suffixes land there.
Everything is derived from id, ssp, gcm and rcp instead.
add_scenario_cols( df, pathways = default_pathways, low_warming_gcms = c("GFDL", "MPI", "MRI"), lower_emission_rcps = "2.6" )add_scenario_cols( df, pathways = default_pathways, low_warming_gcms = c("GFDL", "MPI", "MRI"), lower_emission_rcps = "2.6" )
df |
Data with |
pathways |
Table of |
low_warming_gcms |
GCMs classed as "Low warming". |
lower_emission_rcps |
RCPs classed as "Lower emission". |
Adds:
b4t"None", the CG region where B4T is implemented, or "All CG regions".
ensemble"Climate" or "B4T".
pathwayName of the SSP x RCP combination from pathways
(e.g. "Green world"), or "SSPx-RCPy" if not listed.
warming"Lower emission" for lower_emission_rcps; otherwise
"Low warming" / "High warming" by GCM; "No climate change" for NoCC.
and resets co2 / co2_fert (all runs are without CO2 fertilization).
df with the added columns.
Aquatic commodities are missing from Nutrients_per_kg.gdx. These are
rough, globally generic approximations (same value for every country),
informed by FAO/INFOODS uFiSh ranges and USDA food composition data for
representative species in each IMPACT aquatic category.
aquatic_nutrient_per_kgaquatic_nutrient_per_kg
A tibble with columns cmdty, Nutrients and value.
Caveats: not country-specific; rough averages across highly variable species
groups (small whole fish vs. large fillet fish differ by an order of
magnitude for vitamin A, iron, zinc, folate). Treat as a placeholder and flag
as a known limitation. Units match Nutrients codes, per kg edible portion, raw.
The six CG regions plus "All CG regions" (the CG6 scenario).
b4t_levelsb4t_levels
A character vector.
CGIAR regions where Breeding For Tomorrow (B4T) is implemented
b4t_regionsb4t_regions
A character vector of CG region codes.
Each B4T run against the climate run with the same SSP, GCM and RCP
(climate_counterpart(), e.g. SSP3-MRI-370-WCA vs SSP3-MRI-370-379)
in target_year, so B4T runs under any scenario are handled.
gap = distance from target (0 if met); gap_closed = share of the
counterfactual's gap closed by B4T (NA if it already meets the target).
build_b4t_comparison( df, value_col, threshold = NULL, threshold_col = NULL, direction = c("below", "above"), target_year = 2050 )build_b4t_comparison( df, value_col, threshold = NULL, threshold_col = NULL, direction = c("below", "above"), target_year = 2050 )
df |
Indicator data with scenario columns (climate + B4T runs). |
value_col |
Column with the indicator value. |
threshold, threshold_col
|
Fixed or dynamic target. |
direction |
|
target_year |
Year compared. |
One row per region x B4T run with counterfactual (base_id,
base_*) and B4T values, absolute and percent change, gaps, gap closed
and target status change.
B4T comparisons for a list of indicator specs
build_b4t_comparisons(specs, ...)build_b4t_comparisons(specs, ...)
specs |
Indicator specs (see |
... |
Further arguments to |
All comparisons stacked, with an indicator column.
For each region, the share of scenarios hitting the target in
target_year, and a classification tree (rpart) on the scenario descriptors
for regions where some but not all scenarios hit it. Run on the climate
ensemble (filter_climate()).
build_pathway_analysis( df, value_col, threshold = NULL, threshold_col = NULL, direction = c("below", "above"), target_year = 2050, predictors = c("pathway", "warming") )build_pathway_analysis( df, value_col, threshold = NULL, threshold_col = NULL, direction = c("below", "above"), target_year = 2050, predictors = c("pathway", "warming") )
df |
Indicator data with scenario columns. |
value_col |
Column with the indicator value. |
threshold |
Fixed target value. |
threshold_col |
Column with a region/year-specific target (dynamic
target, e.g. |
direction |
|
target_year |
Year evaluated. |
predictors |
Scenario columns used by the trees. |
A list with df_year, summary_tbl, partial_regions,
tree_results and rules_tbl.
Read from the regions sheet of a GFSir mapping file, which is long: one
row per (cty, region) membership. Cached after the first call.
cg_lookup(mapping = "mappingCG6.xlsx")cg_lookup(mapping = "mappingCG6.xlsx")
mapping |
GFSir mapping file name. |
A tibble with columns cty and cg_region.
The climate (non-B4T) run with the same SSP, GCM and RCP, e.g.
SSP3-MRI-370-WCA -> SSP3-MRI-370-379. Used to compare each B4T run
with its own counterfactual.
climate_counterpart(id)climate_counterpart(id)
id |
Scenario id(s). |
Scenario id(s) of the matching climate run.
SSP3, MRI climate model, RCP 7.0, no CO2 fertilization.
crio_baseline_idcrio_baseline_id
A character string.
Runs every figure type for a set of indicators and writes them to
plotdir. Each figure type and each indicator can be switched on or off,
and a failing figure is reported and skipped instead of stopping the run.
crio_plot_all( fulldata, plotdir, plots = c("maps", "pct_hits", "rules", "trajectories", "trajectories_countries", "quantities", "overview", "b4t_heatmap", "b4t_gap"), indicators = NULL, nutrients = TRUE, regions = c(b4t_regions, "WLD"), countries = NULL, ctymap = NULL, specs = NULL, nut_threshold = 1.5, water_threshold = 1, keep_above = -0.1, b4t_map_scenario = "All CG regions", b4t_show_regions = c("all", "own"), b4t_show_countries = c("own", "all"), baseline_id = crio_baseline_id, target_year = 2050, subdirs = TRUE, format = "png" )crio_plot_all( fulldata, plotdir, plots = c("maps", "pct_hits", "rules", "trajectories", "trajectories_countries", "quantities", "overview", "b4t_heatmap", "b4t_gap"), indicators = NULL, nutrients = TRUE, regions = c(b4t_regions, "WLD"), countries = NULL, ctymap = NULL, specs = NULL, nut_threshold = 1.5, water_threshold = 1, keep_above = -0.1, b4t_map_scenario = "All CG regions", b4t_show_regions = c("all", "own"), b4t_show_countries = c("own", "all"), baseline_id = crio_baseline_id, target_year = 2050, subdirs = TRUE, format = "png" )
fulldata |
Output of |
plotdir |
Output folder (created if needed). |
plots |
Figure types to make (see Details). Default: all. |
indicators |
Indicator names from |
nutrients |
Include the nutrient adequacy indicators when
|
regions |
Region codes for regional figures. |
countries |
Country codes for country figures. |
ctymap |
Region map from |
specs |
Indicator specs. Default |
nut_threshold, water_threshold
|
Passed to |
keep_above |
|
b4t_map_scenario |
B4T run mapped in the |
b4t_show_regions, b4t_show_countries
|
B4T lines in trajectory figures for
|
baseline_id |
Baseline scenario id. |
target_year |
Year evaluated for maps, pathway analysis and B4T comparisons. |
subdirs |
Write each figure type to its own subfolder of |
format |
File extension for figures ( |
Figure types (plots):
maps4-panel indicator maps (climate ensemble). Needs ctymap.
pct_hitsBar chart of percent of climate scenarios hitting the target.
rulesHeatmap of decision-tree rules across regions.
trajectoriesTrajectories for regions (all B4T runs).
trajectories_countriesTrajectories for countries (own-region B4T).
quantitiesNutrient quantity trajectories (RNI and target lines),
for regions and, if given, countries.
overviewDistance-to-target overviews (main indicators and
nutrients), for regions and, if given, countries.
b4t_heatmapRegion x B4T heatmaps (absolute and percent change).
b4t_gapGap closed by B4T (bars) and gap maps for b4t_map_scenario.
Invisibly, a list with analyses (pathway analyses by indicator),
b4t (all B4T comparisons) and failed (figures that errored, with
the message).
Combinations not listed here are named automatically as "SSPx-RCPy".
Pass your own table to add_scenario_cols() (via load_crio_data()) to
rename or add pathways.
default_pathwaysdefault_pathways
A tibble with columns ssp, rcp (as parsed by GFSir, e.g.
"2.6", "7.0") and pathway.
Raw/intermediate commodities that would double count, plus palm kernel (food availability only in IDN and MYS, and small).
exclude_cmdtyexclude_cmdty
A character vector of IMPACT demand commodity codes.
Extract rules from a classification tree
extract_rules(tree, region_name)extract_rules(tree, region_name)
tree |
An rpart tree. |
region_name |
Region code to tag the rules with. |
A data frame with region, outcome ("hits"/"misses"), rule, cover.
Drops B4T runs, leaving the SSP x GCM x RCP runs (including the baseline).
filter_climate(df)filter_climate(df)
df |
Data with an |
Filtered df.
Food groups used for calorie and water totals
food_groupsfood_groups
A character vector of GFSir food group codes.
ADER comes from FAOSTAT Food Security and is extended to future years with a linear trend per country.
get_ader(calories, faostat_csv, sets_xlsx, years = 2025:2050)get_ader(calories, faostat_csv, sets_xlsx, years = 2025:2050)
calories |
Output of |
faostat_csv |
Path to FAOSTAT |
sets_xlsx |
Path to the IMPACT |
years |
Years to extrapolate ADER to. |
Total calories with ader and hits_target.
Adds a Total row over food_groups and each row's share of the total.
GRL is dropped (no demand except fish).
get_calories(files, mapping = "mappingCG6.xlsx")get_calories(files, mapping = "mappingCG6.xlsx")
files |
Scenario GDX files (see |
mapping |
GFSir mapping file name. |
Calories (kcal/person/day).
Food availability (all commodities and food groups)
get_foodavail(files, mapping = "mappingCG6.xlsx")get_foodavail(files, mapping = "mappingCG6.xlsx")
files |
Scenario GDX files (see |
mapping |
GFSir mapping file name. |
GFSir foodavail output for all scenarios (no scenario columns).
Fruit and vegetable availability (g/person/day)
get_frtveg(foodavail)get_frtveg(foodavail)
foodavail |
Output of |
F&V availability.
Hunger is only solved in 5-year steps; GFSir's group5 merges it onto
annual population, so the in-between years come back as 0. Only years with
hunger results are kept.
get_hunger(files, mapping = "mappingCG6.xlsx")get_hunger(files, mapping = "mappingCG6.xlsx")
files |
Scenario GDX files (see |
mapping |
GFSir mapping file name. |
Note: the hunger module floors the share at risk at 1 percent, scaled to each country's FAO 2020 numbers, so countries can flatten at a country-specific minimum (e.g. ~3.3 percent for CIV).
Hunger data with value (million people) and share.
Total calories against the minimum dietary energy requirement (MDER)
get_mder(calories, minkcal)get_mder(calories, minkcal)
calories |
Output of |
minkcal |
Output of |
Total calories with minKCAL and hits_target.
Minimum calorie requirement by country
get_minkcal(gdx)get_minkcal(gdx)
gdx |
A scenario GDX file containing |
A data frame with region and minKCAL.
Food availability (kg/person/day) x nutrient content per kg, summed over
commodities, divided by the RNI. Nutrient contents come from the Hunger
model's Nutrients_per_kg.gdx (country-specific) plus
aquatic_nutrient_per_kg placeholders for aquatic foods.
get_nutrient_adequacy( foodavail, nutrients_gdx, mapping = "mappingCG6.xlsx", rni = rni_lookup, aquatic = aquatic_nutrient_per_kg, exclude = exclude_cmdty )get_nutrient_adequacy( foodavail, nutrients_gdx, mapping = "mappingCG6.xlsx", rni = rni_lookup, aquatic = aquatic_nutrient_per_kg, exclude = exclude_cmdty )
foodavail |
Output of |
nutrients_gdx |
Path to |
mapping |
GFSir mapping file name (commodity mapping from its |
rni |
RNI table (default rni_lookup). |
aquatic |
Aquatic nutrient values (default aquatic_nutrient_per_kg). |
exclude |
Commodities to exclude (default exclude_cmdty). |
This is nutrient supply, not intake.
One row per region x year x scenario x nutrient with
total_nutrient (per capita per day), RNI and adequacy_ratio.
Countries with total blue water below min_volume in the baseline in 2025
are dropped. ratio2025 is each value over its own 2025 value.
get_water( files, mapping = "mappingCG6.xlsx", baseline_id = crio_baseline_id, min_volume = 0.01 )get_water( files, mapping = "mappingCG6.xlsx", baseline_id = crio_baseline_id, min_volume = 0.01 )
files |
Scenario GDX files (see |
mapping |
GFSir mapping file name. |
baseline_id |
Baseline scenario id. |
min_volume |
Minimum 2025 baseline total (cubic km) to keep a country. |
Blue water data (cubic km).
One entry per indicator with its data, target and labels. Used to drive trajectory figures, distance-to-target overviews and B4T comparisons in a loop.
indicator_specs(fulldata, nut_threshold = 1.5, water_threshold = 1)indicator_specs(fulldata, nut_threshold = 1.5, water_threshold = 1)
fulldata |
Output of |
nut_threshold |
Nutrient adequacy target as a multiple of the RNI. |
water_threshold |
Target for blue water use relative to 2025. |
Each entry has: df, value_col, threshold or threshold_col,
direction ("below" or "above" the target is good), label,
optional short_label, labeller (axis labels) and delta_labeller
(absolute change vs baseline; shares in percentage points).
A named list of specs. The names of the non-nutrient indicators are
stored in attr(, "main").
Climate runs are named SSP-GCM-RCP-379 (no CO2 fertilization), e.g.
SSP1-GFDL-126-379 or SSP3-MRI-370-379. B4T runs replace the last
segment with the CG region where B4T is implemented (CWANA, ESA, ...,
CG6 = all CG regions). Any SSP (1-5), GCM and RCP is picked up; you can
also pass your own vector of files to the readers instead.
list_scenarios(scendir, include_nocc = FALSE)list_scenarios(scendir, include_nocc = FALSE)
scendir |
Folder with scenario GDX files. |
include_nocc |
Keep |
Character vector of full file paths.
Build all RIO indicator datasets
load_crio_data( files, nutrients_gdx, faostat_csv, sets_xlsx, mapping = "mappingCG6.xlsx", baseline_id = crio_baseline_id )load_crio_data( files, nutrients_gdx, faostat_csv, sets_xlsx, mapping = "mappingCG6.xlsx", baseline_id = crio_baseline_id )
files |
Scenario GDX files (see |
nutrients_gdx |
Path to |
faostat_csv |
Path to the FAOSTAT Food Security csv (for ADER). |
sets_xlsx |
Path to IMPACT |
mapping |
GFSir mapping file name. |
baseline_id |
Baseline scenario id; its GDX supplies |
A named list: hunger, fruits_and_vegetables, calories,
fats, sugar, MDER, ADER, RNI, WATER, minkcal.
Load the IMPACT region shapefile
load_region_map(shp)load_region_map(shp)
shp |
Path to the IMPACT regions shapefile (with a |
A SpatVector.
Display names for nutrient codes
nutrient_labelsnutrient_labels
A named character vector, names are Nutrients codes.
Nutrient availability in physical units (per capita per day) instead of
adequacy ratios. The target is nut_threshold x RNI; the RNI itself is
added as a reference line (ref_value).
nutrient_quantity_specs(fulldata, nut_threshold = 1.5)nutrient_quantity_specs(fulldata, nut_threshold = 1.5)
fulldata |
Output of |
nut_threshold |
Nutrient adequacy target as a multiple of the RNI. |
A named list of specs (names are nutrient codes), with title,
ref_value and ref_label set.
CG region a region code belongs to
own_cg_region(r, mapping = "mappingCG6.xlsx")own_cg_region(r, mapping = "mappingCG6.xlsx")
r |
Region codes (countries and/or CG regions). |
mapping |
GFSir mapping file name. |
The code itself for CG regions, the CG region for countries, NA
for anything else (WLD, DVD/DVG, countries outside CG regions).
Bar chart, one panel per region.
plot_b4t_gap_closed( cmp, regions = c(b4t_regions, "WLD"), indicator_label = "target", baseline_id = crio_baseline_id, title = NULL, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 6 )plot_b4t_gap_closed( cmp, regions = c(b4t_regions, "WLD"), indicator_label = "target", baseline_id = crio_baseline_id, title = NULL, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 6 )
cmp |
Output of |
regions |
Region codes (panels). |
indicator_label |
Indicator name for the y axis and title. |
baseline_id |
Climate run whose B4T runs are shown. |
title |
Plot title. |
save, outfile, plotdir, width, height
|
Saving options. |
A ggplot.
(A) baseline gap; (B) gap under the B4T run; (C) change in value vs baseline; (D) share of the baseline gap closed.
plot_b4t_gap_maps( cmp, ctymap, b4t_scenario = "All CG regions", baseline_id = crio_baseline_id, direction = c("below", "above"), gap_labeller = scales::label_number(), delta_labeller = scales::label_number(), indicator_label = "indicator", target_year = 2050, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 6 )plot_b4t_gap_maps( cmp, ctymap, b4t_scenario = "All CG regions", baseline_id = crio_baseline_id, direction = c("below", "above"), gap_labeller = scales::label_number(), delta_labeller = scales::label_number(), indicator_label = "indicator", target_year = 2050, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 6 )
cmp |
Output of |
ctymap |
Region map from |
b4t_scenario |
B4T run to map (a CG region or |
baseline_id |
Climate run whose B4T runs are shown. |
direction |
|
gap_labeller |
Label function for gaps. |
delta_labeller |
Label function for the change in value. |
indicator_label |
Indicator name for titles. |
target_year |
Year (titles). |
save, outfile, plotdir, width, height
|
Saving options. |
A ggarrange object.
Fill = percent change vs baseline; tile text = absolute change (top) and percent change (bottom). Own-region effects sit on the diagonal.
plot_b4t_heatmap( cmp, regions = c(b4t_regions, "WLD"), direction = c("below", "above"), delta_labeller = scales::label_number(accuracy = 0.01, style_positive = "plus"), pct_labeller = scales::percent_format(accuracy = 0.01, style_positive = "plus"), baseline_id = crio_baseline_id, title = NULL, save = FALSE, outfile = NULL, plotdir = ".", width = 8, height = 5.5 )plot_b4t_heatmap( cmp, regions = c(b4t_regions, "WLD"), direction = c("below", "above"), delta_labeller = scales::label_number(accuracy = 0.01, style_positive = "plus"), pct_labeller = scales::percent_format(accuracy = 0.01, style_positive = "plus"), baseline_id = crio_baseline_id, title = NULL, save = FALSE, outfile = NULL, plotdir = ".", width = 8, height = 5.5 )
cmp |
Output of |
regions |
Region codes (rows). |
direction |
|
delta_labeller, pct_labeller
|
Label functions for absolute and percent change. |
baseline_id |
Climate run whose B4T runs are shown (B4T runs are compared with this run). |
title |
Plot title. |
save, outfile, plotdir, width, height
|
Saving options. |
A ggplot.
Puts all indicators on one scale: gap = (value - target) / target for "below" targets and (target - value) / target for "above" targets, so a positive gap is short of target and zero or negative is target met. Lines are the baseline; markers are B4T in the panel's own CG region (open circle) and in all CG regions (cross). WLD and countries outside CG regions have no own-region run.
plot_gap_overview( specs, regions = c(b4t_regions, "WLD"), keep_above = NULL, target_year = 2050, baseline_id = crio_baseline_id, mapping = "mappingCG6.xlsx", title = "Distance to target", save = FALSE, outfile = NULL, plotdir = ".", width = 12, height = 8 )plot_gap_overview( specs, regions = c(b4t_regions, "WLD"), keep_above = NULL, target_year = 2050, baseline_id = crio_baseline_id, mapping = "mappingCG6.xlsx", title = "Distance to target", save = FALSE, outfile = NULL, plotdir = ".", width = 12, height = 8 )
specs |
Indicator specs (see |
regions |
Region codes: CG regions and/or countries. |
keep_above |
If set, keep only region x indicator lines whose baseline
gap in |
target_year |
Year used by |
baseline_id |
Baseline scenario id. |
mapping |
GFSir mapping file (for country -> CG region). |
title |
Plot title. |
save, outfile, plotdir, width, height
|
Saving options. |
A ggplot.
(A) baseline value in baseline_year; (B) mean across scenarios in
target_year; (C) baseline distance from target in target_year;
(D) percent of scenarios hitting the target. Rest-of-world countries
(row_countries) are greyed out.
plot_indicator_maps( df, summary_tbl, ctymap, value_col, baseline_id = crio_baseline_id, threshold = NULL, threshold_col = NULL, direction = c("below", "above"), indicator_label, value_labeller = scales::percent_format(accuracy = 1), target_year = 2050, baseline_year = 2025, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 6 )plot_indicator_maps( df, summary_tbl, ctymap, value_col, baseline_id = crio_baseline_id, threshold = NULL, threshold_col = NULL, direction = c("below", "above"), indicator_label, value_labeller = scales::percent_format(accuracy = 1), target_year = 2050, baseline_year = 2025, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 6 )
df |
Indicator data (normally the climate ensemble, |
summary_tbl |
|
ctymap |
Region map from |
value_col |
Column with the indicator value. |
baseline_id |
Baseline scenario id. |
threshold, threshold_col
|
Fixed or dynamic target (see |
direction |
|
indicator_label |
Label for titles and legends. |
value_labeller |
Label function for values. |
target_year, baseline_year
|
Years for panels. |
save, outfile, plotdir, width, height
|
Saving options. |
With a fixed threshold the value scales diverge at the target; with a
dynamic threshold_col they use a simple gradient.
A ggarrange object.
Regions where some but not all scenarios hit the target.
plot_pct_hits(analysis, title = "% scenarios hitting target")plot_pct_hits(analysis, title = "% scenarios hitting target")
analysis |
Output of |
title |
Plot title. |
A ggplot.
Plot the classification tree for one region
plot_region_tree(analysis, region_code, title = NULL)plot_region_tree(analysis, region_code, title = NULL)
analysis |
Output of |
region_code |
Region code. |
title |
Plot title. |
Called for its side effect (base graphics plot).
Heatmap of tree rules across regions
plot_rules_heatmap( analysis, outcome_filter = "hits", title = "Pathways by region", wrap_width = 30, base_size = 11, save = FALSE, outfile = NULL, plotdir = ".", width = 18, height = 14 )plot_rules_heatmap( analysis, outcome_filter = "hits", title = "Pathways by region", wrap_width = 30, base_size = 11, save = FALSE, outfile = NULL, plotdir = ".", width = 18, height = 14 )
analysis |
Output of |
outcome_filter |
|
title |
Plot title. |
wrap_width |
Wrap width for rule labels. |
base_size |
Base font size. |
save, outfile, plotdir, width, height
|
Saving options. |
A ggplot.
Convenience wrapper: passes a spec from indicator_specs() or
nutrient_quantity_specs() to plot_target_trajectories().
plot_spec_trajectories(spec, ...)plot_spec_trajectories(spec, ...)
spec |
One spec entry. |
... |
Further arguments to |
A ggplot.
Line figure over time, one panel per region. Bands show the range across GCMs for each pathway (SSP x RCP, climate ensemble); the black line is the baseline; coloured lines are the B4T runs built on the baseline (same SSP, GCM and RCP); the dashed line is the target.
plot_target_trajectories( df, value_col, threshold = NULL, threshold_col = NULL, regions = c(b4t_regions, "WLD"), b4t_show = c("all", "own"), ref_value = NULL, ref_label = "reference", baseline_id = crio_baseline_id, mapping = "mappingCG6.xlsx", indicator_label, value_labeller = scales::label_number(), title = NULL, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 7 )plot_target_trajectories( df, value_col, threshold = NULL, threshold_col = NULL, regions = c(b4t_regions, "WLD"), b4t_show = c("all", "own"), ref_value = NULL, ref_label = "reference", baseline_id = crio_baseline_id, mapping = "mappingCG6.xlsx", indicator_label, value_labeller = scales::label_number(), title = NULL, save = FALSE, outfile = NULL, plotdir = ".", width = 10, height = 7 )
df |
Indicator data with scenario columns (climate + B4T ensembles). |
value_col |
Column with the indicator value. |
threshold, threshold_col
|
Fixed or dynamic target. A dynamic target follows the baseline's values over time. |
regions |
Region codes: CG regions and/or countries (e.g. |
b4t_show |
|
ref_value |
Optional extra horizontal reference line (dotted), e.g. the RNI when the target is a multiple of it. |
ref_label |
Name of the reference line in the subtitle. |
baseline_id |
Baseline scenario id. |
mapping |
GFSir mapping file (for country -> CG region). |
indicator_label |
Y axis label. |
value_labeller |
Label function for the y axis. |
title |
Plot title. |
save, outfile, plotdir, width, height
|
Saving options. |
Note: if all GCMs give the same value (e.g. hunger at the model's floor), a band has zero width and is not visible.
A ggplot.
Calls a GFSir reader (e.g. GFSir::group5()) on each GDX file, adds the
scenario id and binds the results.
read_scenarios(files, fun, ...)read_scenarios(files, fun, ...)
files |
GDX file paths. |
fun |
GFSir reader function taking |
... |
Further arguments passed to |
A data.table with all scenarios stacked.
Re-applies add_scenario_cols() to every element of fulldata, e.g. to
rename pathways or change the GCM classification without re-reading GDXs.
relabel_scenarios(fulldata, ...)relabel_scenarios(fulldata, ...)
fulldata |
Output of |
... |
Arguments to |
fulldata with updated scenario columns.
Adult RNIs per capita per day, from Sherwin's GTAP paper. Units are in the nutrient code suffix (g, mg, mcg).
rni_lookuprni_lookup
A tibble with columns Nutrients and RNI.
Rest-of-world countries greyed out on maps
row_countriesrow_countries
A character vector of IMPACT region codes.
One file per element of fulldata. CSVs keep only food groups, their
commodities and totals where a name column exists.
save_crio_data(fulldata, rdsdir = NULL, csvdir = NULL, suffix = "")save_crio_data(fulldata, rdsdir = NULL, csvdir = NULL, suffix = "")
fulldata |
Output of |
rdsdir |
Folder for RDS files ( |
csvdir |
Folder for CSV files ( |
suffix |
Suffix added to CSV file names, e.g. |
fulldata, invisibly.
Scenario id from a GDX file path
scenario_id(gdx)scenario_id(gdx)
gdx |
GDX file path(s). |
File name without folder and .gdx extension.
Filters every element of fulldata that has scenario columns, so all
later figures and tables use only the chosen runs. NULL keeps everything
for that dimension.
select_scenarios( fulldata, ssp = NULL, rcp = NULL, gcm = NULL, b4t = NULL, ids = NULL )select_scenarios( fulldata, ssp = NULL, rcp = NULL, gcm = NULL, b4t = NULL, ids = NULL )
fulldata |
Output of |
ssp |
SSPs to keep, e.g. |
rcp |
RCPs to keep, as parsed by GFSir, e.g. |
gcm |
GCMs to keep, e.g. |
b4t |
B4T values to keep: |
ids |
Scenario ids to keep. |
fulldata with filtered elements.
Summarise tree rules by region and outcome
summarise_rules(rules_tbl)summarise_rules(rules_tbl)
rules_tbl |
|
One row per region with total cover, number of rules and the rules for "hits" and "misses".
Built from the maps package, without Antarctica, dissolved into one
outline. Cached after the first call.
world_outline()world_outline()
A SpatVector.