GitLab at IIASA

test.R 1.97 KiB
Newer Older
product_list %>% filter(code == "SUNO")


plotList <- function(nplots) {
  lapply(seq_len(nplots), function(x) plot_ly())
}
fig <- subplot(p1, p2)

nodes1 = nodes_position(biofuels_ln_baseline[[2]])
links1 = biofuels_ln_baseline[[1]]

links2 <- biofuels_ln[[1]]
nodes2 <- nodes_position(biofuels_ln[[2]])

fig <- plot_ly(
  width = 1000,
  height = 800,
  type = "sankey",
  # domain = list(
  #   x =  c(0,1),
  #   y =  c(0,1)
  # ),
  orientation = "h",
  arrangement = 'snap',
  valueformat = ".0f",
  valuesuffix = " tonnes",

  node = list(
    label = nodes$label,
    color = nodes$color,
    x = nodes$level_x,
    y= nodes$level_y,
    pad = 20,
    thickness = 15,
    line = list(
      color = "blau",
      width = 1
    )
  ),

  link = list(
    source = links$source,
    target = links$target,
    value =  links$value,
    color = links$color
    #label =  links$group
  )
)  %>% layout(
  autosize = F,
  margin = list(l=10, r=10, b=50, t=50, pad=40),
  title = "Market Balance in Tonnens",
  font = list(size = 13, family ="Arial"),
  xaxis = list(showgrid = F, zeroline = F),
  yaxis = list(showgrid = F, zeroline = F)
)
convert_supply_details(region_list= "EU", product_list= "MAIZ", scenario_list= sanky_file1, folder = gdx.dir)

diff_perc_supply_details <- function(b,s){
  diff_all <- bind_rows(b,s) %>%
    # evaluate following calls for each value in the rowname column
    group_by(Commodities) %>%
    # add all non-grouping variables
    summarise(across(everything(), diff, .names = "diff_{col}"))
  # diff_all

  print(diff_all)
  percent = data.frame(Commodities = b$Commodities) %>% as_tibble()

  for (i in 1:(ncol(s)-1)){
    percent <- bind_cols(round(s[i]/b[i] *100-100, 1), percent)
    #volumn <- bind_cols(round(sum(oil_cake_market_Scenario[i,1:7]) / sum(oil_cake_market_baseline[i,1:7])*100-100, 1), percent)
  }
  percent$volume <- NA
  for (i in 1:nrow(s)) percent$volume[i] <- (sum(s[i,1:4])/sum(b[i,1:4])*100-100)

  all <- full_join(diff_all, percent)
  print(all)
}