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
imports example data set for plotting.process_input_data()
performs the initial processing on raw input
data in banks’ format.example_data <- process_input_data(example_data)
plot_trajectory()
create a trajectory alignment chart in a ggplot
object.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()
prepares pre-processed data for
plotting a tech-mix chart.get_r2dii_technology_colours()
get the predefined technology
colors for a sector.plot_techmix()
create a techmix chart in a ggplot object.# 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()
.plot_timelineA()
creates a time line plot.# 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()
creates the default specs data frame for
‘plot_timelinea()’.r2dii_palette_colours()
outputs a data frame giving the 2dii
colour palette.# You may use it as a template to create your custom specs
timeline_specs(data)
#> # A tibble: 4 x 3
#> line_name label colour_hex
#> <chr> <chr> <chr>
#> 1 projected Projected #1b324f
#> 2 corporate_economy Corporate Economy #00c082
#> 3 target_demo Target Demo #ff9623
#> 4 adjusted_scenario_demo Adjusted Scenario Demo #d0d7e1
# You may use it as a reference for 2DII's colour palette
r2dii_palette_colours()
#> # A tibble: 9 x 2
#> label colour_hex
#> <chr> <chr>
#> 1 dark_blue #1b324f
#> 2 green #00c082
#> 3 orange #ff9623
#> 4 grey #d0d7e1
#> 5 dark_purple #574099
#> 6 yellow #f2e06e
#> 7 soft_blue #78c4d6
#> 8 ruby_red #a63d57
#> 9 moss_green #4a5e54
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.