"inst/examples/use.case1_market_balances_sankey_tables.R" did not exist on "3534f02304c75a3d2bc82f581943f1f90c939b41"
Newer
Older
############################################################################
############################################################################
### ###
### SECTION 1: ###
### SANKEY CHARTS AND TABLES ###
### ###
############################################################################
############################################################################
#################################################################
## Setup ##
#################################################################
# set currently working directory
gdx.dir <- paste0(getwd(), "/inst/extdata/gdx")
# define gdx file name for reading
sanky_file1 <- "res_2_1230cap_after_2014_refdefaultA" # refdefautA
sanky_file2 <- "res_2_1230fta_import_bandefaultA" # bandefaultA
# loaded gdx files and saved in dataout
outdata.dir <- paste0(getwd(), "/inst/outdata")
prod_list = c("WHEA","MAIZ","BARL","RAPE","SUNF","PULS",
"DDGS","SUGR","ACQU", "SOYC", "OCER","SOYA",
"RAPO","POUM","RAPC","SUNC","BIOE","SOYO",
Xinxin Yang
committed
###################################################################################################
## Get detailed balance tables (demand broken down to its comoponents) ##
###################################################################################################
balance_detailed_Baseline <- convert_balance_detailed("EU",
prod_list,
sanky_file1,
folder = gdx.dir)
balance_detailed_Scenario <- convert_balance_detailed("EU",
prod_list,
sanky_file2,
folder = gdx.dir)
#################################################################
## Sankey charts ##
#################################################################
Xinxin Yang
committed
baseline_biofuels <- prelinks(balance_detailed = balance_detailed_Baseline, p_biofuels = T, products = dimdef_product)
scenario_biofuels <- prelinks(balance_detailed = balance_detailed_Scenario, p_biofuels = T, products = dimdef_product)
Xinxin Yang
committed
baseline <- prelinks(balance_detailed = balance_detailed_Baseline, p_biofuels = FALSE, products = dimdef_product)
scenario <- prelinks(balance_detailed = balance_detailed_Scenario, p_biofuels = FALSE, products = dimdef_product)
# get links and nodes for different selected market
Xinxin Yang
committed
biofuels_ln_baseline <- links_nodes(baseline_biofuels, scenario_biofuels, p_baseline =TRUE, fixedNodePosition = FALSE,
products = dimdef_product, dim5s = dimdef_dim5)
Xinxin Yang
committed
biofuels_ln <- links_nodes(baseline_biofuels, scenario_biofuels, p_baseline = FALSE, fixedNodePosition = FALSE,
products = dimdef_product, dim5s = dimdef_dim5)
Xinxin Yang
committed
ln_baseline <- links_nodes(baseline, scenario, TRUE, fixedNodePosition = FALSE,
products = dimdef_product, dim5s = dimdef_dim5)
Xinxin Yang
committed
ln <- links_nodes(baseline, scenario, FALSE,fixedNodePosition = FALSE,
products = dimdef_product, dim5s = dimdef_dim5)
plot_sankey(biofuels_ln_baseline,p_baseline = TRUE,png = FALSE,outdata.dir = outdata.dir)
plot_sankey(biofuels_ln,p_baseline = FALSE,png = FALSE,outdata.dir = outdata.dir)
plot_sankey(ln_baseline,p_baseline =TRUE,png = FALSE,outdata.dir = outdata.dir)
plot_sankey(ln, p_baseline = FALSE,png = FALSE,outdata.dir= outdata.dir)
Xinxin Yang
committed
cake_oil_m <- combine_dfs(biofuels_ln_baseline, biofuels_ln,SidebySide = FALSE)
plot_sankey(cake_oil_m,p_baseline = TRUE,png = TRUE, outdata.dir= outdata.dir)
Xinxin Yang
committed
cereals_m <- combine_dfs(ln_baseline, ln, SidebySide = FALSE)
plot_sankey(cereals_m,p_baseline = TRUE,png = TRUE, outdata.dir= outdata.dir)
##################################################################
## Tables ##
##################################################################
# List of commodities for the market balances table
# oil cake market balance
# A list if long commodities name
oil_cake_market_list= c("Rape seed",
"Soya seed",
"Sunflower seed",
"Rape seed oil",
"Soya oil",
"Sunflower seed oil",
"Soya cake",
"Sunflowe seed cake",
"Rape seed cake",
"Destilled dried grains from bio-ethanol processing",
"Pulses",
"Bio ethanol")
# or A List of commodities' key
oil_cake_key_list = c("RAPE","SUNF","SOYA","PULS","RAPO","SUNO","SOYO", "RAPC", "SUNC","SOYC","BIOE","DDGS")
Xinxin Yang
committed
b_oil_cake <- filter_market_balance(balance_detailed_Baseline, oil_cake_market_list, dimdef_product)
b_oil_cake <- filter_market_balance(balance_detailed_Baseline, oil_cake_key_list, dimdef_product)
Xinxin Yang
committed
s_oil_cake <- filter_market_balance(balance_detailed_Scenario, oil_cake_market_list, dimdef_product)
s_oil_cake <- filter_market_balance(balance_detailed_Scenario, oil_cake_key_list, dimdef_product)
# calculate the absolute and percentage changes between baseline and scenario.
Xinxin Yang
committed
oil_cake <- cal_diff_percentage_change(b_oil_cake,s_oil_cake,supply_details = FALSE)
Xinxin Yang
committed
oil_cake_tb <- nicetable_market_balances(oil_cake,"baseline for oil and cake markets") %>%
tab_footnote(
locations = cells_stub(rows = c(2)),
footnote = md("Destilled dried grains from bio-ethanol processing")
)%>%
gtsave(
webshot(paste0(outdata.dir,"/oil_cake_tb.html"),paste0(outdata.dir,"/png/","oil_cake_tb.png"),
vwidth = 1100)
# cereals, meate.. balance market ----
cereals_list <- c("Barley",
"Grain maize",
"Other cereals",
"Wheat",
"Poultry meat",
"Rice milled",
"Sugar","Fish and other acquatic products")
# basline: load balance market.
b_cereals <- filter_market_balance(balance_detailed_Baseline, cereals_list)
# Scenario: load balance market.
s_cereals <- filter_market_balance(balance_detailed_Scenario, cereals_list)
# calculate the absolute and percentage changes between baseline and scenario.
Xinxin Yang
committed
cereals <- cal_diff_percentage_change(b_cereals,s_cereals,supply_details = FALSE)
Xinxin Yang
committed
cereals_tb <- nicetable_market_balances(cereals,"baseline for cereals, sugar, and meat markets") %>%
webshot(paste0(outdata.dir,"/cereals_tb.html"),paste0(outdata.dir,"/png/","cereals_tb.png"),