# Institutionaaliset tapahtumat kontekstia varten
tapahtumat <- tribble(
~vuosi, ~teksti,
1973, "UK/DK/IE\nliittyminen",
1986, "Yhtenäis-\neuroppa-asiak.",
1993, "Sisämarkkinat\n(Maastricht)",
1995, "AT/FI/SE\nliittyminen",
2004, "Itä-Eurooppa\nliittyminen",
2009, "Lissabon"
)
p_ts <- ggplot(bcp_df, aes(vuosi, n_yht)) +
# Taustamerkinnät institutionaalisille tapahtumille
geom_vline(data = tapahtumat, aes(xintercept = vuosi),
linetype = "dotted", color = "grey70", linewidth = 0.4) +
geom_col(fill = col_blue, alpha = 0.5, width = 0.8) +
# Posteriori-keskiarvo = mallin estimoima "taso" kullakin hetkellä
geom_line(aes(y = post_mean), color = col_red,
linewidth = 1.2) +
geom_text(data = tapahtumat,
aes(x = vuosi, y = Inf, label = teksti),
vjust = 1.3, size = 2.4, color = "grey50", linewidth = 0.3) +
scale_x_continuous(breaks = seq(1960, 2023, 5)) +
scale_y_continuous(labels = comma_format(big.mark = " ")) +
labs(
title = "EU:n säädöstuotanto ja **posteriori-keskiarvo**",
subtitle = "Punainen viiva = bcp-mallin estimoima taso. Hypyt kertovat rakenteellisista muutoksista.",
x = NULL, y = "Säädösten lukumäärä"
)
p_prob <- ggplot(bcp_df, aes(vuosi, post_prob)) +
geom_hline(yintercept = c(0.2, 0.5), linetype = "dashed",
color = c(col_orange, col_red), linewidth = 0.6) +
geom_col(aes(fill = post_prob > 0.5), width = 0.8, show.legend = FALSE) +
scale_fill_manual(values = c(col_blue, col_red)) +
annotate("text", x = 1962, y = 0.52, label = "Vahva evidenssi (p > 0.5)",
color = col_red, size = 3, hjust = 0) +
annotate("text", x = 1962, y = 0.22, label = "Kohtalainen evidenssi (p > 0.2)",
color = col_orange, size = 3, hjust = 0) +
scale_x_continuous(breaks = seq(1960, 2023, 5)) +
scale_y_continuous(labels = percent_format(), limits = c(0, 1)) +
labs(
title = "**Posterioritodennäköisyys muutospisteelle** vuosittain",
subtitle = "Tämä on se, mitä trendiviiva ei näytä: epävarmuus muutoksen ajankohdasta",
x = NULL, y = "P(muutospiste)",
caption = "Malli: bcp (Barry & Hartigan 1993), p0 = 0.2, MCMC = 5000. Lähde: EUR-Lex via eurlex (R).\nKristian Vepsäläinen / kristianvepsalainen.com"
)
p_ts / p_prob + plot_layout(heights = c(2, 1))