section_names <- c(
"Fuchsröhre",
"Flugplatz",
"Döttinger Höhe",
"Karussell",
"Brünnchen"
)
featured_raceways <- raceways |>
filter(raceway_name %in% section_names)
section_descriptions <- tibble::tribble(
~section, ~description,
"Fuchsröhre", "Named after a fox in a construction pipe.",
"Flugplatz", "Named after the former glider airfield.",
"Döttinger Höhe", "Named after nearby Döttingen.",
"Karussell", "Famous banked turn linked to Caracciola.",
"Brünnchen", "The YouTube corner, famous for Touristenfahrten fails."
)
track_sections <- featured_raceways |>
mutate(section = raceway_name) |>
group_by(section) |>
summarise() |>
mutate(section_label = if_else(section == "Karussell", "Caracciola-Karussell", section)) |>
left_join(section_descriptions, by = "section") |>
mutate(label = section_label)
# Densify the same section lines so the annotation stays tied to the full segment.
section_hull_points <- track_sections |>
sf::st_segmentize(dfMaxLength = 25) |>
sf::st_cast("POINT", warn = FALSE)
section_xy <- sf::st_coordinates(section_hull_points)
section_hull_points <- section_hull_points |>
mutate(
x = section_xy[, 1],
y = section_xy[, 2]
)
# Fix annotation anchors around the outside of the track instead of letting them float.
section_label_positions <- tibble::tribble(
~section, ~x_frac, ~y_frac,
"Fuchsröhre", 0.14, 0.72,
"Flugplatz", 0.20, 0.28,
"Döttinger Höhe", 0.60, 0.27,
"Karussell", 0.68, 0.86,
"Brünnchen", 0.80, 0.64
) |>
mutate(
x0 = map_bbox[["xmin"]] + x_frac * (map_bbox[["xmax"]] - map_bbox[["xmin"]]),
y0 = map_bbox[["ymin"]] + y_frac * (map_bbox[["ymax"]] - map_bbox[["ymin"]])
) |>
select(section, x0, y0)
section_hull_points <- section_hull_points |>
left_join(section_label_positions, by = "section")
sections_background <- "#29452F"
sections_track <- "#788993"
sections_highlight <- "#E6D6A8"
sections_annotation <- "#C7D4CA"
p_sections <- ggplot() +
geom_sf(
data = raceways,
colour = sections_track,
linewidth = 0.70,
lineend = "round"
) +
# Keep the same line weight and distinguish selected sections only by colour.
geom_sf(
data = track_sections,
colour = sections_highlight,
linewidth = 0.70,
lineend = "round",
inherit.aes = FALSE
) +
ggforce::geom_mark_hull(
data = section_hull_points,
aes(
x = x,
y = y,
x0 = x0,
y0 = y0,
group = section,
label = label,
description = description
),
# Hide the hull itself; retain only its annotation connector and label.
colour = NA,
fill = NA,
size = 0,
concavity = 2,
expand = grid::unit(1.5, "mm"),
radius = grid::unit(1, "mm"),
label.minwidth = grid::unit(28, "mm"),
label.buffer = grid::unit(1.5, "mm"),
# Let a little of the map background show through the annotation box.
label.fill = grDevices::adjustcolor(sections_background, alpha.f = 0.82),
label.colour = "#F1F5F2",
label.fontsize = c(7, 6),
label.family = map_font,
con.colour = sections_annotation,
con.size = 0.25,
con.type = "elbow",
inherit.aes = FALSE
) +
annotate(
"text",
x = map_bbox[["xmin"]] + 0.025 * (map_bbox[["xmax"]] - map_bbox[["xmin"]]),
y = map_bbox[["ymax"]] - 0.035 * (map_bbox[["ymax"]] - map_bbox[["ymin"]]),
label = "NORDSCHLEIFE",
family = map_font,
fontface = "bold",
size = 3.9,
colour = "#F1F5F2",
hjust = 0,
vjust = 1
) +
theme_void(base_family = map_font) +
theme(
panel.background = element_rect(fill = sections_background, colour = NA),
plot.background = element_rect(fill = sections_background, colour = NA),
plot.margin = margin(0, 0, 0, 0)
) +
map_credit(colour = "#D3E0D1") +
map_coords
p_sections