# Plots Präsi Szenarios Partner. ----------------------------------------------------

# Ausgaben. -------------------------------------------------------------------------
# sim <-
#   read_delim("~/data/appl-wb/20_staff/kjo/szen_einnahmen.csv") %>%
#   filter(type == "exp") %>%
#   select(- type)

p1 <-
  ggplot(sim) +
  # geom_ribbon(aes(x = year, ymin = low, ymax = high,
  #                 col = as.factor(scen),
  #                 fill = as.factor(scen)), alpha = .2) +
  geom_line(aes(x = year, y = mid, col = as.factor(scen)), linewidth = .5, alpha = .5, lty = 2) +
  geom_shadowpoint(aes(x = year, y = mid, col = as.factor(scen)), size = 2) +
  labs(x = NULL,
       y = NULL,
       # y = ifelse(par$real,
       #            "Millionen Franken (real, Preisbasis 2024)\n",
       #            "Millionen Franken (laufende Preise)\n"),
       title = "AHV-Ausgabenprojektion (real, Preise 2024)") +
  theme_grey(base_size = 22, base_family = "Garamond") +
  scale_colour_viridis_d(labels = c("mittel", "hoch", "tief"),
                         name = "Ausgaben-Szenarios (nur Demografie)  ", option = "B", end = .75) +
  # scale_fill_viridis_d(labels   = c("mittel", "hoch", "tief"),
  #                        name = "Ausgaben-Szenarios (nur Demografie)  ", option = "B", end = .75) +
  scale_y_continuous(limits = c(50000, 81000), labels = comma) +
  theme(legend.position = "top")

p2 <-
  ggplot(sim) +
  geom_ribbon(aes(x = year, ymin = low, ymax = high,
                  # col = as.factor(scen),
                  fill = as.factor(scen)), alpha = .2) +
  geom_line(aes(x = year, y = mid, col = as.factor(scen)), linewidth = .5, alpha = .5, lty = 2) +
  geom_shadowpoint(aes(x = year, y = mid, col = as.factor(scen)), size = 2) +
  labs(x = NULL,
       y = NULL,
       # y = ifelse(par$real,
       #            "Millionen Franken (real, Preisbasis 2024)\n",
       #            "Millionen Franken (laufende Preise)\n"),
       title = "AHV-Ausgabenprojektion (real, Preise 2024)") +
  theme_grey(base_size = 22, base_family = "Garamond") +
  scale_colour_viridis_d(labels = c("mittel", "hoch", "tief"),
                         name = "Ausgaben-Szenarios (Demografie + Durchschnittsrenten)  ", option = "B", end = .75) +
  scale_fill_viridis_d(labels   = c("mittel", "hoch", "tief"),
                       name = "Ausgaben-Szenarios (Demografie + Durchschnittsrenten)  ", option = "B", end = .75) +
  scale_y_continuous(labels = comma, limits = c(50000, 81000)) +
  theme(legend.position = "top")

sim2 <- sim %>%
  mutate(low  = ifelse(scen == "B", low , NA),
         mid  = ifelse(scen == "A", mid , NA),
         high = ifelse(scen == "C", high, NA)) %>%
  pivot_longer(cols = low:high) %>%
  na.omit() %>%
  ungroup() %>%
  select(- scen) %>%
  pivot_wider()

p3 <-
  ggplot(sim) +
  # geom_ribbon(aes(x = year, ymin = low, ymax = high), alpha = .2) +
  geom_ribbon(data = sim2,
              aes(x = year, ymin = low, ymax = high), alpha = .25, fill = "mediumpurple1") +
  geom_line(data = sim2, aes(x = year, y = mid), linewidth = .5, alpha = .5, lty = 2) +
  geom_shadowpoint(data = sim2, aes(x = year, y = mid, col = "A"), size = 2) +
  labs(x = NULL,
       y = NULL,
       # y = ifelse(par$real,
       #            "Millionen Franken (real, Preisbasis 2024)\n",
       #            "Millionen Franken (laufende Preise)\n"),
       title = "AHV-Ausgabenprojektion (real, Preise 2024)") +
  theme_grey(base_size = 22, base_family = "Garamond") +
  scale_colour_viridis_d(labels = c("Basisszenario"),
                         name = "Implizite Ausgaben-Bänder des Umlage-Szenarios  ", option = "B", end = .75) +
  scale_fill_viridis_d(labels   = c("Basisszenario"),
                       name = "Implizite Ausgaben-Bänder des Umlage-Szenarios  ", option = "B", end = .75) +
  scale_y_continuous(labels = comma, limits = c(50000, 81000)) +
  theme(legend.position = "top")

# Einnahmen. -------------------------------------------------------------------------
SE <-
  read_delim("~/data/appl-wb/20_staff/kjo/szen_einnahmen.csv") %>%
  filter(type == "inc")

p1 <-
  ggplot(SE) +
  # geom_ribbon(aes(x = year, ymin = low, ymax = high,
  #                 col = as.factor(scen),
  #                 fill = as.factor(scen)), alpha = .2) +
  geom_line(aes(x = year, y = mid, col = as.factor(scen)), linewidth = .5, alpha = .5, lty = 2) +
  geom_shadowpoint(aes(x = year, y = mid, col = as.factor(scen)), size = 2) +
  labs(x = NULL,
       y = NULL,
       # y = ifelse(par$real,
       #            "Millionen Franken (real, Preisbasis 2024)\n",
       #            "Millionen Franken (laufende Preise)\n"),
       title = "AHV-Einnahmenprojektion (real, Preise 2024)") +
  theme_grey(base_size = 22, base_family = "Garamond") +
  scale_colour_viridis_d(labels = c("mittel", "hoch", "tief"),
                         name = "Einnahmen-Szenarios (nur Demografie)  ", option = "B", end = .75) +
  scale_fill_viridis_d(labels   = c("mittel", "hoch", "tief"),
                       name = "Einnahmen-Szenarios (nur Demografie)  ", option = "B", end = .75) +
  scale_y_continuous(labels = comma, limits = c(51000, 81000)) +
  theme(legend.position = "top")

p2 <-
  ggplot(SE) +
  geom_ribbon(aes(x = year, ymin = low, ymax = high,
                  # col = as.factor(scen),
                  fill = as.factor(scen)), alpha = .2) +
  geom_line(aes(x = year, y = mid, col = as.factor(scen)), linewidth = .5, alpha = .5, lty = 2) +
  geom_shadowpoint(aes(x = year, y = mid, col = as.factor(scen)), size = 2) +
  labs(x = NULL,
       y = NULL,
       # y = ifelse(par$real,
       #            "Millionen Franken (real, Preisbasis 2024)\n",
       #            "Millionen Franken (laufende Preise)\n"),
       title = "AHV-Einnahmenprojektion (real, Preise 2024)") +
  theme_grey(base_size = 22, base_family = "Garamond") +
  scale_colour_viridis_d(labels = c("mittel", "hoch", "tief"),
                         name = "Einnahmen-Szenarios (Demografie + Strukturfaktor)  ", option = "B", end = .75) +
  scale_fill_viridis_d(labels   = c("mittel", "hoch", "tief"),
                       name = "Einnahmen-Szenarios (Demografie + Strukturfaktor)  ", option = "B", end = .75) +
  scale_y_continuous(labels = comma, limits = c(51000, 81000)) +
  theme(legend.position = "top")

SE2 <- SE %>%
  mutate(low  = ifelse(scen == "C", low , NA),
         mid  = ifelse(scen == "A", mid , NA),
         high = ifelse(scen == "B", high, NA)) %>%
  pivot_longer(cols = low:high) %>%
  na.omit() %>%
  ungroup() %>%
  select(- scen) %>%
  pivot_wider()

p3 <-
  ggplot(SE) +
  # geom_ribbon(aes(x = year, ymin = low, ymax = high), alpha = .2) +
  geom_ribbon(data = SE2,
              aes(x = year, ymin = low, ymax = high), alpha = .25, fill = "mediumpurple1") +
  geom_line(data = SE2, aes(x = year, y = mid), linewidth = .5, alpha = .5, lty = 2) +
  geom_shadowpoint(data = SE2, aes(x = year, y = mid, col = "A"), size = 2) +
  labs(x = NULL,
       y = NULL,
       # y = ifelse(par$real,
       #            "Millionen Franken (real, Preisbasis 2024)\n",
       #            "Millionen Franken (laufende Preise)\n"),
       title = "AHV-Einnahmenprojektion (real, Preise 2024)") +
  theme_grey(base_size = 22, base_family = "Garamond") +
  scale_colour_viridis_d(labels = c("Basisszenario"),
                         name = "Implizite Einnahmen-Bänder des Umlage-Szenarios  ", option = "B", end = .75) +
  scale_fill_viridis_d(labels   = c("Basisszenario"),
                       name = "Implizite Einnahmen-Bänder des Umlage-Szenarios  ", option = "B", end = .75) +
  scale_y_continuous(labels = comma, limits = c(51000, 81000)) +
  theme(legend.position = "top")
