knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", fig.align = "left", out.width = "100%" ) #' Pull the title of a documented object #' This function helps keep README and help files in sync. #' @param name String. The name of a documented object. #' @return String. #' @examples #' pull_title("plot_trajectory") pull_title <- function(name, db = enframe_documentation("r2dii.plot.static")) { is_name <- db$name == name out <- db$title[is_name] tolower(out) } enframe_documentation <- function(package) { db <- utils::hsearch_db(package, lib.loc = locate_package(package))[["Base"]] names(db) <- tolower(names(db)) db } locate_package <- function(pkg) { locate <- function(path) any(grepl(pkg, list.files(path))) has_pkg <- unlist(lapply(.libPaths(), locate)) .libPaths()[has_pkg][[1]] }
The goal of r2dii.plot.static is to provide users with plotting and data
processing functions that will allow the users to create standard 2DII plots
using PACTA_analysis
or banks' output data as input. The plots are in the form
of ggplot objects.
You can install the development version of r2dii.plot.static from GitHub with:
# install.packages("devtools") devtools::install_github("2DegreesInvesting/r2dii.plot.static")
How to minimize installation errors?
library(dplyr, warn.conflicts = FALSE) library(ggplot2, warn.conflicts = FALSE) library(r2dii.plot.static)
example_data
r pull_title("example_data")
.process_input_data()
r pull_title("process_input_data")
.example_data <- process_input_data(example_data)
plot_trajectory()
r pull_title("plot_trajectory")
.data_trajectory <- prepare_for_trajectory_chart( example_data, sector_filter = "power", technology_filter = "renewablescap", region_filter = "global", scenario_source_filter = "demo_2020", value_name = "production", end_year_filter = 2025, normalize_to_start_year = TRUE ) scenario_specs <- tibble( scenario = c("sds", "sps", "cps"), label = c("SDS", "STEPS", "CPS") ) main_line_metric <- tibble( metric = "projected", label = "Portfolio" ) additional_line_metrics <- tibble( metric = "corporate_economy", label = "Corporate Economy" ) plot_trajectory( data_trajectory, scenario_specs_good_to_bad = scenario_specs, main_line_metric = main_line_metric, additional_line_metrics = additional_line_metrics )
prepare_for_techmix_chart()
r pull_title("prepare_for_techmix_chart")
.get_r2dii_technology_colours()
r pull_title("get_r2dii_technology_colours")
.plot_techmix()
r pull_title("plot_techmix")
.# Default colours, all data, added title sector <- "power" data <- prepare_for_techmix_chart(example_data, sector_filter = sector, years_filter = c(2020, 2025), region_filter = "global", scenario_source_filter = "demo_2020", scenario_filter = "sds", value_to_plot = "technology_share" ) plot <- plot_techmix(data) plot + ggplot2::labs(title = "Technology mix for the Power sector") # Custom colours, all data, no title power_colors_custom <- tibble( technology = c("coalcap", "oilcap", "gascap", "nuclearcap", "hydrocap", "renewablescap"), label = c("Coal Capacity", "Oil Capacity", "Gas Capacity", "Nuclear Capacity", "Hydro Capacity", "Renewables Capacity"), colour = c("black", "brown", "grey", "red", "blue", "green4") ) plot <- plot_techmix(data, tech_colours = power_colors_custom ) plot # Default colours, selected data and labels (metric_type parameters), added title sector <- "automotive" data <- prepare_for_techmix_chart(example_data, sector_filter = sector, years_filter = c(2020, 2025), region_filter = "global", scenario_source_filter = "demo_2020", scenario_filter = "sds", value_to_plot = "technology_share" ) metric_type_order = c( "portfolio_2020", "benchmark_2020", "portfolio_2025", "benchmark_2025", "scenario_2025" ) metric_type_labels = c( "Portfolio 2020", "Benchmark 2020", "Portfolio 2025", "Benchmark 2025", "Target SDS 2025" ) plot <- plot_techmix(data, metric_type_order = metric_type_order, metric_type_labels = metric_type_labels ) plot + ggplot2::labs(title = "Technology mix for the Automotive sector")
prepare_for_timelineA()
r pull_title("prepare_for_timeline")
.plot_timelineA()
r pull_title("plot_timelineA")
.# Using default preparation and specs data <- prepare_for_timelineA(sda_target, sector_filter = "cement") plot_timelineA(data) # Using custom preparation data <- prepare_for_timelineA( sda_target, sector_filter = "cement", year_start = 2020, year_end = 2050, column_line_names = "emission_factor_metric", value_to_plot = "emission_factor_value", extrapolate_missing_values = TRUE ) # Using custom specs and extending the plot with ggplot2 plot_timelineA(data) + labs( title = "Emission intensity trend for Cement.", x = "Year", y = "Tons of CO2 per ton", caption = "Dashed line is an extrapolation of the last value in the dataset." )
timeline_specs()
r pull_title("timeline_specs")
.r2dii_palette_colours()
r pull_title("r2dii_palette_colours")
.# You may use it as a template to create your custom specs timeline_specs(data) # You may use it as a reference for 2DII's colour palette r2dii_palette_colours()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.