Skip to contents

This function adds a column of ggplot2 graphs to a completed allocation tables data frame. The graphs are stored in a list column named plots.

Usage

alloc_plots_df(
  .df,
  countries,
  data_col = "Data",
  plots = "Plots",
  country = IEATools::iea_cols$country,
  ef_product = IEATools::template_cols$ef_product,
  destination = IEATools::template_cols$destination,
  quantity = IEATools::template_cols$quantity,
  c_source = IEATools::template_cols$c_source,
  year = IEATools::iea_cols$year,
  .values = IEATools::template_cols$.values,
  machine = IEATools::template_cols$machine,
  eu_product = IEATools::template_cols$eu_product
)

Arguments

.df

The completed allocation tables data frame. Default is drake::readd(completed_allocation_tables_target, path = cache_path, character_only = TRUE).

countries

The countries for which allocation plots are to be created.

data_col

The name of the output column containing nested data for allocation graphs. Default is "Data".

plots

The name of the output column containing allocation graphs. Default is "Plots".

country

See IEATools::iea_cols.

ef_product, destination, quantity, c_source

See IEATools::template_cols.

year

See IEATools::iea_cols. Passed to alloc_graph().

.values, machine, eu_product

See IEATools::template_cols. Passed to alloc_graph().

Value

A data frame containing a list column of ggplot2 allocation graphs.

Details

The data frame is grouped by all variables needed to create the allocation graph, specifically country, ef_product, and destination and nested prior to making the graphs, namely machine, eu_product, quantity, year, .values, and c_source, meaning that one allocation graph is constructed for each combination of those variables.

Examples

# Make a simple data frame with the expected structure.
alloc_table <- tibble::tribble(~Country, ~Method, ~Energy.type, ~Year, ~Ef.product, ~Destination,
                               ~.values, ~Machine, ~Quantity, ~Eu.product, ~C.source,
                               "GHA", "PCM", "E", 1971, "Gasoline", "Transport",
                               0.5, "Cars", "C_1 [%]", "MD", "World",
                               "GHA", "PCM", "E", 1971, "Gasoline", "Transport",
                               0.5, "Trucks", "C_2 [%]", "MD", "World",
                               "GHA", "PCM", "E", 2020, "Gasoline", "Transport",
                               0.2, "Cars", "C_1 [%]", "MD", "World",
                               "GHA", "PCM", "E", 2020, "Gasoline", "Transport",
                               0.8, "Trucks", "C_2 [%]", "MD", "World",
                               "ZAF", "PCM", "E", 1971, "Gasoline", "Transport",
                               0.5, "Cars", "C_1 [%]", "MD", "World",
                               "ZAF", "PCM", "E", 1971, "Gasoline", "Transport",
                               0.5, "Trucks", "C_2 [%]", "MD", "World",
                               "ZAF", "PCM", "E", 2020, "Gasoline", "Transport",
                               0.3, "Cars", "C_1 [%]", "MD", "World",
                               "ZAF", "PCM", "E", 2020, "Gasoline", "Transport",
                               0.7, "Trucks", "C_2 [%]", "MD", "World")
alloc_plots_df(alloc_table, c("GHA", "ZAF"))
#> # A tibble: 2 × 7
#> # Groups:   Country, Method, Energy.type, Ef.product, Destination [2]
#>   Country Method Energy.type Ef.product Destination Data             Plots 
#>   <chr>   <chr>  <chr>       <chr>      <chr>       <list>           <list>
#> 1 GHA     PCM    E           Gasoline   Transport   <tibble [4 × 5]> <gg>  
#> 2 ZAF     PCM    E           Gasoline   Transport   <tibble [4 × 5]> <gg>