# Simulate: CPG compliance rate as a function of data lag
n_weeks <- 52
true_rate <- 0.78 + 0.004*1:n_weeks + rnorm(n_weeks, 0, 0.03)
# Dashboard with 2-week lag always shows stale data
lag_weeks <- 2
dashboard_rate <- c(rep(NA, lag_weeks), true_rate[1:(n_weeks-lag_weeks)])
tibble(week=1:n_weeks, true_rate=true_rate, dashboard=dashboard_rate) |>
pivot_longer(-week) |>
filter(!is.na(value)) |>
mutate(name=recode(name, true_rate="Current (true) rate",
dashboard="Dashboard (2-week lag)")) |>
ggplot(aes(week, value, color=name)) +
geom_line(linewidth=1.1) +
scale_color_manual(values=c("#0891b2","#e63946")) +
scale_y_continuous(labels=scales::percent_format()) +
labs(title="A 2-week ETL lag means the dashboard always shows last month's compliance — not today's",
x="Week", y="CPG compliance rate", color=NULL) +
theme_di()


