The goal of r2dii.plot is to help you plot 2DII data in an informative, beautiful, and easy way. It is designed to work smoothly with other “r2dii” packages – r2dii.data, r2dii.match, and r2dii.analysis. It also plays well with the ggplot2 package, which helps you customize your plots.

Your data should have a structure similar to that of the demo datasets in the r2dii.data package.

loanbook <- loanbook_demo
ald <- ald_demo
scenario <- co2_intensity_scenario_demo
region <- region_isos_demo

Your workflow involves functions from the packages r2dii.match and r2dii.analysis.

matched <- loanbook %>%
  match_name(ald) %>%
  prioritize() # Remember to validate matches (see `?prioritize`)

r2dii.plot supports three kinds of plots – emission intensity, techmix, and trajectory. Each plot can be created using two types of functions: qplot_*() for standardized plots and plot_*() for ‘bare’ plots leaving the customization to the user.

For each kind, you’ll need to subset the specific rows you want to plot (for example with subset() or dplyr:filter()). For details see the documented “Requirements” of the argument data of each plot_*() or qplot_*() function (e.g. see ?plot_emission_intensity). If you forget to meet the data requirements the error message should guide you.

‘Quick’ plots

Quick plots allow you to create a good looking plot without extensive knowledge of other R packages. They are perfect to have a quick look into the data and for users who are interested in standard PACTA visualizations. Their common characteristics are:

  • 5 year time span.
  • Formatted data labels.
  • Formatted axis labels.
  • A title (and a subtitle).

Use qplot_emission_intensity() with sda-like data.

matched %>%
  target_sda(ald, co2_intensity_scenario = scenario) %>%
  subset(sector == "cement") %>%
  qplot_emission_intensity()
#> Warning: Removing ald rows where `emission_factor` is NA
#> Removing data before 2020 -- the start year of 'projected'.

Use qplot_trajectory() with market_share-like data.

matched %>%
  target_market_share(ald, scenario = scenario_demo_2020, region_isos = region) %>%
  subset(technology == "renewablescap" & region == "global") %>%
  qplot_trajectory()
#> Removing data before 2020 -- the start year of 'projected'.
#> Normalizing `production` values to 2020 -- the start year.

Use qplot_techmix() with market_share-like data.

matched %>%
  target_market_share(ald, scenario = scenario_demo_2020, region_isos = region) %>%
  subset(
    sector == "power" &
      region == "global" &
      metric %in% c("projected", "corporate_economy", "target_sds")
  ) %>%
  qplot_techmix()
#> Removing data before 2020 -- the start year of 'projected'.
#> The `technology_share` values are plotted for extreme years.
#> Do you want to plot different years? E.g. filter . with:`subset(., year %in% c(2020, 2030))`.

Plots

The plot_*() functions show the data as they are and allow you to add your own customization by modifying the input (for example by adding a column ‘label’ or ‘label_tech’ for changing the data labels) or using ggplot2 functions to
modify elements of the plot.

The basic output of plot_emission_intensity() looks rather unappealing.

p <- matched %>%
  target_sda(ald, co2_intensity_scenario = scenario) %>%
  subset(sector == "cement") %>%
  plot_emission_intensity()
#> Warning: Removing ald rows where `emission_factor` is NA
#> Removing data before 2020 -- the start year of 'projected'.
p

You can polish your plot by modifying the input and the output ggplot object. Your options are limitless but these are some typical things you may do:

  • Change the time span.
  • Add custom labels by modifying the column ‘metric’ and technology of market_share-like data.
  • Add a title and a subtitle.
  • Change x and y axis labels.
  • Customize the colours and legend labels with ggplot2::scale_colour_manual().

For example, here is how you might customize each of the three kinds of plots:

data <- sda %>%
  filter(
    sector == "cement",
    year <= 2030
  )

plot_emission_intensity(data) +
  labs(
    title = "Emission intensity plot for cement",
    x = "Time",
    y = "Tons of CO2 per ton of cement produced"
  ) +
  scale_color_manual(
    values = c("#4a5e54", "#a63d57", "#78c4d6", "#f2e06e"),
    labels = c("Proj.", "Corp. Economy", "Target (demo)", "Adj. Scenario (demo)")
  )
#> Removing data before 2020 -- the start year of 'projected'.
#> Scale for 'colour' is already present. Adding another scale for 'colour',
#> which will replace the existing scale.

matched %>%
  target_market_share(ald, scenario = scenario_demo_2020, region_isos = region) %>%
  filter(
    technology == "renewablescap",
    region == "global",
    year <= 2030
  ) %>%
  mutate(
    label = case_when(
      metric == "projected" ~ "Your Portfolio",
      metric == "corporate_economy" ~ "Benchmark (Corp. Economy)",
      metric == "target_sds" ~ "Sustainable Development Scen.",
      metric == "target_sps" ~ "Stated Policies Scen.",
      metric == "target_cps" ~ "Current Policy Scen.",
      TRUE ~ metric
    )
  ) %>%
  plot_trajectory() +
  scale_x_continuous(n.breaks = 3) +
  labs(
    title = "Portfolio Scenario Alignment for Renewables Technology",
    x = "Year",
    y = "Production normalized to start year"
  ) +
  theme(
    plot.margin = unit(c(0.5, 6, 0.5, 1), "cm")
  )
#> Removing data before 2020 -- the start year of 'projected'.
#> Normalizing `production` values to 2020 -- the start year.

data <- market_share %>%
  filter(
    metric %in% c("projected", "corporate_economy", "target_sds"),
    sector == "power",
    region == "global",
    year >= 2021,
    year <= 2040 # custom time range
  ) %>%
  mutate(
    label = case_when(
      metric == "projected" ~ "Your Portfolio",
      metric == "corporate_economy" ~ "Corporate Economy Benchmark",
      metric == "target_sds" ~ "SDS Scenario"
    )
  )

plot_techmix(data) +
  scale_fill_manual(
    values = c("black", "brown", "grey", "blue", "green4"),
    labels = paste(c("Coal", "Oil", "Gas", "Hydro", "Renewables"), "Cap.")
  )
#> The `technology_share` values are plotted for extreme years.
#> Do you want to plot different years? E.g. filter data with:`subset(data, year %in% c(2020, 2030))`.
#> Scale for 'fill' is already present. Adding another scale for 'fill', which
#> will replace the existing scale.