Skip to content

Commit

Permalink
add emission market target deviation plot
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Oct 30, 2023
1 parent ca0234e commit bfe0c8e
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion R/mipConvergence.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ mipConvergence <- function(gdx) { # nolint cyclocomp_linter

priceAnticipationPlotly <- ggplotly(priceAnticipation, tooltip = c("text"))

# Tax Convergence ----
# Tax Convergence (optional) ----

cmTaxConvCheck <- as.vector(readGDX(gdx, name = "cm_TaxConvCheck"))

Expand Down Expand Up @@ -387,6 +387,68 @@ mipConvergence <- function(gdx) { # nolint cyclocomp_linter

taxConvergencePlotly <- ggplotly(taxConvergence, tooltip = c("text"))


# Emission Market Deviation (optional) ----

optionalPlots <- list()

p80EmiMktTargetDevIter <- suppressWarnings(
readGDX(gdx, name = "p80_emiMktTarget_dev_iter", react = "silent", restore_zeros = FALSE)
)

if (!is.null(p80EmiMktTargetDevIter)) {
cmEmiMktTargetTolerance <- as.vector(readGDX(gdx, name = "cm_emiMktTarget_tolerance"))

p80EmiMktTargetDevIter <- p80EmiMktTargetDevIter %>%
as.quitte() %>%
select("period", "iteration", "ext_regi", "emiMktExt", "value") %>%
mutate("converged" = .data$value <= cmEmiMktTargetTolerance)

data <- p80EmiMktTargetDevIter %>%
group_by(.data$iteration) %>%
summarise(converged = ifelse(any(.data$converged == FALSE), "no", "yes")) %>%
mutate("tooltip" = "Converged")

# TODO: What to add to the tooltip if not converged?

for (i in unique(p80EmiMktTargetDevIter$iteration)) {
if (data[data$iteration == i, "converged"] == "no") {
tmp <- filter(p80EmiMktTargetDevIter, .data$iteration == i, .data$converged == FALSE)

data[data$iteration == i, "tooltip"] <- paste0(
"Iteration ", i, " ",
"not converged:<br>",
paste0(unique(tmp$ext_regi), collapse = ", "),
"<br>",
paste0(unique(tmp$period), collapse = ", "),
"<br>",
paste0(unique(tmp$emiMktExt), collapse = ", ")
)
}
}

emiMktTargetDev <- suppressWarnings(ggplot(data, aes_(
x = ~iteration, y = "Emission Market\nTarget Deviation",
fill = ~converged, text = ~tooltip
))) +
geom_hline(yintercept = 0) +
theme_minimal() +
geom_point(size = 2, alpha = aestethics$alpha) +
scale_fill_manual(values = booleanColor) +
scale_y_discrete(breaks = c("Emission Market\nTarget Deviation"), drop = FALSE) +
labs(x = NULL, y = NULL)

emiMktTargetDevPlotly <- ggplotly(emiMktTargetDev, tooltip = c("text"))

optionalPlots <- append(optionalPlots, list(emiMktTargetDevPlotly))
}

# Implicity Quantity Target (optional) ----

# Global Bugdet Deviation (optional) ----

# Internalized Damages (optional) ----

# Summary plot ----

out <- list()
Expand All @@ -409,5 +471,14 @@ mipConvergence <- function(gdx) { # nolint cyclocomp_linter

out$tradeDetailPlot <- surplusConvergencePlotly

if (length(optionalPlots) > 0) {
out$optionalPlots <- subplot(
optionalPlots
) %>%
hide_legend() %>%
config(displayModeBar = FALSE, displaylogo = FALSE) %>%
layout(margin = list(l = -100, r = 10))
}

return(out)
}

0 comments on commit bfe0c8e

Please sign in to comment.