I was playing with How Six Great Metros Grew, an interactive piece on Highcharts Vibes. Six networks grow on maps while you move through the years. London gets a head start; Beijing catches up rather quickly.
While watching, I thought: I could plot the length of each network by year! There was my next little project. Then I scrolled down. The chart was already there. Of course it was.
Well, there goes my idea. But wait… they missed the chance to make a metro plot. What’s a metro plot? A line chart with little white-centered circles, like stations on a metro map. That’s what I’m calling it, anyway :P.
And since I was going to borrow the data, I wanted to add Santiago, Mexico City, Madrid, and Tokyo to the comparison. For Tokyo, I’m combining Tokyo Metro and Toei Subway, leaving the suburban railways out.
First, the tracks
Citylines has a public API, so let’s get the sections directly from there and select the networks we want.
Download and prepare the API data
# Keep a local snapshot, so each run uses the same source data.
# Delete a snapshot file to request a fresh copy from its endpoint.
fetch_snapshot <- function(url, snapshot) {
if (!file.exists(snapshot)) {
request(url) |>
req_user_agent("Mozilla/5.0 (metro-growth-example)") |>
req_timeout(60) |>
req_perform(path = snapshot)
}
paste(readLines(snapshot, warn = FALSE, encoding = "UTF-8"), collapse = "\n")
}
city_systems <- tibble::tribble(
~slug, ~city, ~systems,
"london", "London", "(TfL) Underground",
# Nord-Sud's lines became part of the Paris metro; include their earlier history.
"paris", "Paris", "M\u00e9tro de Paris|Nord-Sud",
"moscow", "Moscow", "Moscow Metro",
"beijing", "Beijing", "Beijing Subway",
"los-angeles", "Los Angeles", "LA Metro Rail",
"tokyo", "Tokyo", "Tokyo Metro|Toei Subway",
"santiago-de-chile", "Santiago", "Metro de Santiago",
"mexico-city", "Mexico City", "Sistema de Transporte Colectivo (STC)",
"madrid", "Madrid", "Metro"
)
citylines_sections <- bind_rows(lapply(seq_len(nrow(city_systems)), function(i) {
city_data <- city_systems[i, ]
selected_systems <- strsplit(city_data$systems, "|", fixed = TRUE)[[1]]
response <- fetch_snapshot(
paste0("https://www.citylines.co/api/", city_data$slug, "/raw_source/sections"),
paste0(
"blog/posts/2026-12-04-vibing-with-metro-growth/data/sources/",
city_data$slug, ".json"
)
) |>
fromJSON(simplifyVector = FALSE)
bind_rows(lapply(response$features, function(feature) {
section <- feature$properties
metro_lines <- Filter(function(line) {
line$system %in% selected_systems
}, section$lines)
# Exclude planned sections and those without a known opening year.
if (!length(metro_lines) || is.null(section$opening) ||
section$opening <= 0 || section$opening > 2026) return(NULL)
# Track when this section belonged to the selected network, not just
# when the physical railway first opened under a different operator.
intervals <- bind_rows(lapply(metro_lines, function(line) {
tibble(
opening = max(section$opening, if (is.null(line$from)) 0 else line$from),
closure = min(
if (is.null(section$closure)) 999999 else section$closure,
if (is.null(line$to)) 999999 else line$to
)
)
})) |>
filter(opening < closure, opening <= 2026) |>
arrange(opening, closure)
if (!nrow(intervals)) return(NULL)
# Merge overlapping or adjoining service periods. Shared tracks must
# count once in any given year, even when several metro lines use them.
periods <- intervals[1, ]
for (j in seq_len(nrow(intervals))[-1]) {
last <- nrow(periods)
if (intervals$opening[j] <= periods$closure[last]) {
periods$closure[last] <- max(periods$closure[last], intervals$closure[j])
} else {
periods <- bind_rows(periods, intervals[j, ])
}
}
tibble(
city = city_data$city, system = city_data$systems,
section_id = paste0("citylines-", section$id, "-", seq_len(nrow(periods))),
opening = periods$opening,
# Citylines uses 999999 when a section has no closing year.
closure = if_else(periods$closure >= 999999, NA_real_, periods$closure),
# Citylines reports metres; convert them to kilometres.
length_km = section$length / 1000,
source = "Citylines, retrieved 2026-12-04"
)
}))
}))
sections <- citylines_sections
write_csv(
sections,
"blog/posts/2026-12-04-vibing-with-metro-growth/data/metro-sections.csv"
)Each row is a mapped section’s continuous period of metro service, with an opening year, an optional closing year, and a length in kilometres. Some tracks started as ordinary railways, so their metro service can begin later than the track itself. Here’s what we got:
sections |>
select(city, opening, closure, length_km) |>
slice_head(n = 6)# A tibble: 6 x 4
city opening closure length_km
<chr> <dbl> <dbl> <dbl>
1 London 1884 1990 0.428
2 London 1884 1990 1.50
3 London 1868 NA 0.131
4 London 1969 NA 0.929
5 London 1868 NA 0.538
6 London 1892 NA 1.91
To get a network’s length in a given year, add the sections that were open then. A closed section no longer counts. This measures kilometres open in each year, rather than kilometres built during that year.
network_by_year <- sections |>
reframe(
year = 1860:2026,
km = vapply(year, function(y) {
# A section stops counting in its closing year, as in the original.
open <- opening <= y & (is.na(closure) | closure > y)
sum(length_km[open])
}, numeric(1)),
first_year = min(opening),
.by = city
)
network_length <- network_by_year |>
# Start each line when its network opens, rather than at a long row of zeros.
filter(year >= first_year) |>
arrange(city, year) |>
mutate(
# Mark changes, not every unchanged year: those are our "stations".
station = row_number() == 1L | abs(km - lag(km)) > 0.001,
.by = city
)
# Include zero before a network opens, so the set of cities stays constant.
navigator_mean <- network_by_year |>
summarise(km = mean(km), .by = year)These are collaborative, mapped lengths, not audited official network totals; some later extensions may be missing. The selection also mixes metro and light rail in Los Angeles. This isn’t a ranking of the world’s largest metros.
Now, the stations
Each city gets one color. The lines keep their actual values; the metro-map part is just the white centers and colored rims. I only add a circle when the length changes, so a long pause doesn’t become a pile of stations.
city_colors <- c(
# Navy from the UK flag, and teal inspired by Paris public transport.
"London" = "#012169", "Paris" = "#00A88F",
# Blue and red inspired by the Russian and Chinese flags.
"Moscow" = "#0039A6", "Beijing" = "#DE2910",
# Lakers purple for LA; a deeper metro-inspired red for Santiago.
"Los Angeles" = "#552583", "Santiago" = "#A6192E",
# Green and yellow from the Mexican and Spanish flag palettes.
"Mexico City" = "#006847", "Madrid" = "#F1BF00",
# Light blue inspired by Tokyo Metro.
"Tokyo" = "#00A7DB"
)
# Keep one observation per year for the shared tooltip, even without a marker.
metro_series <- map2(names(city_colors), unname(city_colors), function(city_name, city_color) {
city_data <- network_length |>
filter(city == city_name) |>
transmute(
# Calendar range buttons and the navigator use real dates.
x = datetime_to_timestamp(as.Date(paste0(year, "-01-01"))),
y = round(km, 1),
station
)
list(
name = city_name,
color = city_color,
marker = list(lineColor = city_color),
data = pmap(city_data, function(x, y, station) {
list(
x = x, y = y,
marker = list(enabled = station)
)
})
)
})
# Double the previous 480 px height to give the "stations" more space.
metro_plot <- highchart(height = 960) |>
# Use a white canvas, like a printed transit map.
hc_chart(
type = "line", backgroundColor = "#FFFFFF", plotBackgroundColor = "#FFFFFF",
zooming = list(type = "x")
) |>
hc_xAxis(
type = "datetime", title = list(text = NULL),
min = datetime_to_timestamp(as.Date("2006-01-01")),
max = datetime_to_timestamp(as.Date("2026-01-01")),
labels = list(format = "{value:%Y}")
) |>
hc_yAxis(
title = list(text = "Kilometres of network open"), min = 0,
labels = list(format = "{value} km"),
gridLineColor = "#EDF0F3",
opposite = FALSE
) |>
hc_plotOptions(series = list(
lineWidth = 2.5,
# Keep annual observations intact, even when the full history is visible.
dataGrouping = list(enabled = FALSE),
# The navigator gets its own mean series instead of the individual city lines.
showInNavigator = FALSE,
marker = list(
enabled = TRUE, symbol = "circle", radius = 4,
fillColor = "#FFFFFF", lineWidth = 2
),
states = list(hover = list(lineWidthPlus = 0))
)) |>
hc_add_series_list(metro_series) |>
hc_legend(
enabled = TRUE, layout = "proximate", align = "right",
# A short colored line with a white-centered "station", just like the plot.
symbolWidth = 32, symbolHeight = 8, symbolPadding = 8
) |>
hc_navigator(
enabled = TRUE, adaptToUpdatedData = FALSE,
yAxis = list(title = list(text = ""), labels = list(enabled = FALSE)),
series = list(
name = "Mean across networks", type = "line", color = "#080C13",
lineWidth = 1.5, marker = list(enabled = FALSE),
data = map2(
datetime_to_timestamp(as.Date(paste0(navigator_mean$year, "-01-01"))),
navigator_mean$km,
function(x, y) list(x, y)
)
)
) |>
hc_scrollbar(enabled = TRUE) |>
hc_rangeSelector(
enabled = TRUE, selected = 0, inputEnabled = FALSE,
# Reserve enough room for the full year labels and separate the buttons.
buttonTheme = list(width = 88), buttonSpacing = 12,
buttons = list(
list(type = "year", count = 20, text = "20 years"),
list(type = "year", count = 40, text = "40 years"),
list(type = "all", text = "All")
)
) |>
hc_tooltip(
shared = TRUE, table = TRUE, sort = TRUE,
valueDecimals = 1, valueSuffix = " km", xDateFormat = "%Y"
) |>
# On narrow screens, move the legend below and hide the navigation controls.
hc_responsive(rules = list(list(
condition = list(maxWidth = 700),
chartOptions = list(
legend = list(
layout = "horizontal", align = "center", verticalAlign = "bottom"
),
rangeSelector = list(enabled = FALSE),
navigator = list(enabled = FALSE),
scrollbar = list(enabled = FALSE)
)
))) |>
hc_exporting(enabled = FALSE) |>
hc_credits(enabled = FALSE)metro_plotHover over a year and the table sorts the cities from longest to shortest. The chart starts with the last 20 years. Try 40 years or All, or move the handles in the navigator below the plot to pick your own period. The city labels move with the last observation inside the selected period. Its single line shows the annual mean across all nine networks, counting networks that haven’t opened yet as zero. Click a city label to hide its line. Try hiding Beijing: the smaller networks get a little more breathing room.
The circles aren’t actual stations, and a crossing isn’t an interchange. They’re a small visual joke about the subject. The dates and kilometres still do the real work.
References
Highcharts Vibes, 2026. How Six Great Metros Grew — the inspiration for this example.
Citylines contributors. Citylines — the source for nine networks, retrieved directly through its public API on December 4, 2026. The original credits London, Paris, Moscow, Beijing, and Los Angeles. We also use Santiago, Mexico City, Madrid, and Tokyo, combining Tokyo Metro and Toei Subway. Shared sections are counted once, and sections without an opening year or with future opening dates are excluded.
Highsoft. Highcharts legend layout — proximate placement of the city labels.