This file provides some high-level glances at the composite data results (including the variables present, etc.)
knitr::opts_knit$set(root.dir = normalizePath("../")) knitr::opts_chunk$set(echo = FALSE)
source(here::here("scripts/setup.R")) loadd(proj, mac) proj <- factorize_proj(proj, gas_lvl = "gas_grps_2")
# non-co2 breakout within co2/non-co2 context # bar of pies ideas: # https://community.rstudio.com/t/bar-of-pie-chart-in-r-ggplot/48098/4 # for now, stacked bars # stacked bar by gas proj %>% filter(year == 2015) %>% factorize_proj(gas_lvl = "gas_grps_2") %>% ggplot(aes(x = "by-gas-grp", y = value, fill = gas)) + geom_col(position = "stack") + GER_theme() + scale_fill_ger("gases") # stacked bar by sector proj %>% filter(year == 2015) %>% group_by(sector) %>% summarize(along = "sector", value = sum(value, na.rm = TRUE)) %>% ggplot(aes(x = "by-sector", y = value, fill = sector)) + geom_col(position = "stack") + GER_theme() + scale_fill_ger("sectors")
The following values for country, sector, source, subsource, gas, unit, and year are present in the GER composite results:
srcgas_combos <- proj %>% filter(! str_detect(source, "^Other")) %>% distinct(sector, source, gas) %>% group_by(sector, source) %>% summarize(gases = glue::glue_collapse(gas, sep = ", ")) %>% ungroup() kable(srcgas_combos) %>% kable_styling(bootstrap_options = c("condensed"), full_width = FALSE) %>% collapse_rows(columns = c(1, 2))
proj_gas_grps_2 <- proj %>% mutate(gas = if_else(gas %in% c('HFCs', 'PFCs', 'SF6', 'NF3'), 'F-GHGs', as.character(gas))) %>% mutate( sector = factor(sector, levels = sectors), gas = factor(gas, levels = gas_grps_2))
plot_bar_by_var_time_series(proj_gas_grps_2, byvar = gas)
plot_bar_by_var_time_series(proj_gas_grps_2, byvar = sector)
mac_sector <- mac %>% filter(year == 2030) %>% group_by(sector) %>% summarize( no_cost = sum(q[p <= 0], na.rm = TRUE), inc_cost = sum(q[p > 0], na.rm = TRUE)) proj_sector <- proj %>% filter(year == 2030) %>% group_by(sector) %>% summarize(baseline = sum(value, na.rm = TRUE)) mac_all <- full_join(mac_sector, proj_sector, by = "sector") %>% mutate(no_cost_pct = no_cost / baseline, inc_cost_pct = inc_cost / baseline, resid_pct = (baseline - no_cost - inc_cost) / baseline) mac_bars <- mac_all %>% select(sector, no_cost_pct, inc_cost_pct, resid_pct) %>% pivot_longer( cols = c("no_cost_pct", "inc_cost_pct", "resid_pct"), names_to = "reduction_type", values_to = "reduction_pct") %>% mutate(reduction_type = factor(reduction_type, levels = c("resid_pct", "inc_cost_pct", "no_cost_pct"))) mac_bars %>% mutate(sector = fct_rev(factor(sector, levels = sectors))) %>% ggplot(aes(x = sector, y = reduction_pct, fill = reduction_type)) + geom_col() + coord_flip() + scale_fill_ger(guide = guide_legend( direction = "horizontal", reverse = TRUE)) + GER_theme() + theme(legend.position = "bottom")
# TODO: transform mac data to add gas info
# Need: # Projection total by year # Total miti at $0 by year, subtract from baseline to get resid at $0 # Total miti by sector, joined to sector, to get resid by sector
# TODO: make it a map top2030 <- proj %>% filter(year == 2030) %>% group_by(country) %>% summarize(value = sum(value, na.rm = TRUE)) %>% ungroup() %>% arrange(desc(value)) %>% slice(1:5) proj %>% filter(year == 2030) %>% mutate(topcountry = case_when( country %in% top2030$country ~ country, TRUE ~ "Rest of World" )) %>% mutate(topcountry = factor(topcountry, levels = c(top2030$country, "Rest of World"))) %>% arrange(topcountry) %>% group_by(year, topcountry) %>% summarize(value = sum(value, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x="top countries", y=value, fill=topcountry)) + geom_col(position = "stack", linetype = 1, size = 0.5, colour = "white") + GER_theme() + scale_fill_ger("countries")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.