# Generates assets/ceac.png for the dampack page.
#
# Run from this directory:  Rscript make-ceac-figure.R
#
# Needs the development version of dampack, because df_example_psa_elc is not on
# CRAN yet. The figure is generated here and committed, so the page render does
# not depend on a development install. The code below is what the page displays.

suppressPackageStartupMessages({
  library(dampack); library(ggplot2)
})

strategies <- paste0("S", 1:6)

psa <- make_psa_obj(
  cost          = df_example_psa_elc[, 1:6],
  effectiveness = df_example_psa_elc[, 7:12],
  strategies    = strategies,
  currency      = "$"
)

wtp  <- seq(0, 60000, by = 500)
ceac_obj <- ceac(wtp, psa)

print(summary(ceac_obj))

p_ceac <- plot(ceac_obj, frontier = TRUE, points = FALSE)
p_ceac$layers[[2]]$aes_params$colour <- "#ffffff"

p_ceac <- p_ceac +
  labs(title    = "Cost-effectiveness acceptability curves",
       subtitle = "df_example_psa_elc: six strategies, three frontier switches") +
  theme(
    plot.background  = element_rect(fill = NA, color = NA),
    panel.background = element_rect(fill = NA, color = NA),
    legend.background = element_rect(fill = NA, color = NA),
    legend.key       = element_rect(fill = NA, color = NA),
    panel.grid.major = element_line(color = "#ffffff1f"),
    panel.grid.minor = element_blank(),
    axis.line        = element_line(color = "#ffffff55"),
    text             = element_text(color = "#dce6f0"),
    axis.text        = element_text(color = "#dce6f0")
  )

ragg::agg_png("assets/ceac.png", width = 7.5, height = 5.4, units = "in",
              res = 150, background = "transparent")
print(p_ceac)
invisible(dev.off())
