# Distinct time points for clean step-function lines
score_data <- pbp_sb |>
dplyr::filter(!is.na(game_seconds_elapsed)) |>
dplyr::select(game_seconds_elapsed, qtr, sea_pts, ne_pts) |>
dplyr::arrange(game_seconds_elapsed) |>
dplyr::distinct(game_seconds_elapsed, .keep_all = TRUE)
# Scoring events with hover labels (points_scored already in pbp_sb from setup)
score_events <- pbp_sb |>
dplyr::filter(!is.na(points_scored), points_scored > 0, !is.na(posteam)) |>
dplyr::mutate(
annotate_y = dplyr::if_else(posteam == "SEA", sea_pts, ne_pts),
score_type = dplyr::case_when(
touchdown == 1 ~ "Touchdown",
field_goal_result == "made" ~ "Field Goal",
safety == 1 ~ "Safety",
TRUE ~ "Score"
),
hover_text = paste0(
"<b>", posteam, " ", score_type, "</b><br>",
"Q", qtr, " | ", time, "<br>",
"SEA ", sea_pts, " \u2013 NE ", ne_pts, "<br>",
"<i>", stringr::str_trunc(desc, 70), "</i>"
)
) |>
dplyr::arrange(game_seconds_elapsed)
sea_events <- score_events |> dplyr::filter(posteam == "SEA")
ne_events <- score_events |> dplyr::filter(posteam == "NE")
plot_ly() |>
add_trace(
data = score_data, x = ~game_seconds_elapsed, y = ~sea_pts,
type = "scatter", mode = "lines",
line = list(color = sea_green, width = 3, shape = "hv"),
name = "Seattle", hoverinfo = "none"
) |>
add_trace(
data = score_data, x = ~game_seconds_elapsed, y = ~ne_pts,
type = "scatter", mode = "lines",
line = list(color = ne_navy, width = 3, shape = "hv"),
name = "New England", hoverinfo = "none"
) |>
add_trace(
data = sea_events, x = ~game_seconds_elapsed, y = ~annotate_y,
type = "scatter", mode = "markers",
marker = list(color = sea_green, size = 11, symbol = "circle",
line = list(color = "white", width = 2)),
name = "SEA Score", text = ~hover_text,
hoverinfo = "text", showlegend = FALSE
) |>
add_trace(
data = ne_events, x = ~game_seconds_elapsed, y = ~annotate_y,
type = "scatter", mode = "markers",
marker = list(color = ne_navy, size = 11, symbol = "circle",
line = list(color = "white", width = 2)),
name = "NE Score", text = ~hover_text,
hoverinfo = "text", showlegend = FALSE
) |>
layout(
title = list(text = "Super Bowl LX: Score Timeline", font = list(size = 16)),
xaxis = list(title = "", tickvals = qtr_breaks, ticktext = qtr_labels,
gridcolor = "#eeeeee", zeroline = FALSE),
yaxis = list(title = "Points", gridcolor = "#eeeeee", zeroline = TRUE,
zerolinecolor = "#dddddd"),
legend = list(x = 0.02, y = 0.97, bgcolor = "rgba(255,255,255,0.85)",
bordercolor = "#dddddd", borderwidth = 1),
paper_bgcolor = "white", plot_bgcolor = "white",
shapes = qtr_shapes, annotations = qtr_annots
)