Today’s tennis fixtures in R

This vignette reads the day’s tennis schedule from the Live Tennis API into a tibble. It then counts the fixtures by tour and hour, and draws the counts with ggplot2.

Get a free API key

Sign up at https://livetennisapi.com/subscribe/free. No card is needed. The free plan covers fixtures and live matches, at 30 requests a minute and 100 a day.

Put the key in your environment

The package reads the key from the LIVETENNISAPI_KEY environment variable. Put it in ~/.Renviron so every session has it, then restart R:

LIVETENNISAPI_KEY=twjp_...

For one session, set it from the console:

Sys.setenv(LIVETENNISAPI_KEY = "twjp_...")

Read the fixtures

list_fixtures() returns the schedule as a tibble, earliest fixture first. It takes tour, draw, limit and offset. A page holds up to 200 rows, and lta_meta() says whether more rows follow. The loop reads every page, so a busy day is counted in full.

library(livetennisapi)

pages <- list()
offset <- 0
repeat {
  page <- list_fixtures(limit = 200, offset = offset)
  pages[[length(pages) + 1]] <- page
  if (!isTRUE(lta_meta(page)$has_more)) break
  offset <- offset + 200
}
fixtures <- do.call(rbind, pages)
stopifnot("The schedule is empty." = nrow(fixtures) > 0)

today <- Sys.Date()

The output on this page comes from a recorded response that ships with the package. Its players and tournaments are made up, and its date is 10 November 2026. That lets the page build with no key and no network. Your own call returns the same columns with the real schedule. The recorded file is at system.file("extdata", "fixtures.json", package = "livetennisapi").

fixtures[, c("event_date", "start_time", "tour", "tournament", "player1_name", "player2_name")]
#> # A tibble: 26 × 6
#>   event_date start_time           tour           tournament  player1_name     player2_name
#>   <chr>      <chr>                <chr>          <chr>       <chr>            <chr>       
#> 1 2026-11-10 2026-11-10T09:00:00Z challenger_men Stonebridge T. Varnholt      E. Quenby   
#> 2 2026-11-10 2026-11-10T09:00:00Z challenger_men Stonebridge M. Odrazil       P. Skerrow  
#> 3 2026-11-10 2026-11-10T10:00:00Z wta            Port Elm    L. Tamsin-Roe    K. Ebbrey   
#> 4 2026-11-10 2026-11-10T10:30:00Z challenger_men Stonebridge R. Halloway-Dunn S. Brixey   
#> 5 2026-11-10 2026-11-10T10:30:00Z wta            Port Elm    N. Okonjo-Vale   H. Lindqvar 
#> 6 2026-11-10 2026-11-10T11:00:00Z challenger_men Stonebridge D. Peverell      J. Astrup-M…
#> # ℹ 20 more rows

Each row is one fixture. start_time is in UTC, and it stays NA until the order of play gives the fixture a time. status is scheduled, live, finished, cancelled or postponed, and it can be NA.

Reshape the tibble

Keep today’s fixtures that have a start time, then add the hour each one starts. The tour column is the fixture’s own label. It can be finer than the tour filter, and a doubles pair reports it in capitals. Lower-casing it puts singles and doubles on the same tour in one group. A fixture with no label goes under unknown, so it still counts.

today_fx <- fixtures[fixtures$event_date == format(today) & !is.na(fixtures$start_time), ]

start <- as.POSIXct(today_fx$start_time, format = "%Y-%m-%dT%H:%M:%S", tz = "UTC")
today_fx$hour <- as.integer(format(start, "%H", tz = "UTC"))
today_fx$tour <- tolower(today_fx$tour)
today_fx$tour[is.na(today_fx$tour)] <- "unknown"

by_hour <- as.data.frame(
  table(tour = today_fx$tour, hour = today_fx$hour),
  responseName = "fixtures", stringsAsFactors = FALSE
)
by_hour$hour <- as.integer(by_hour$hour)
by_hour <- tibble::as_tibble(by_hour[by_hour$fixtures > 0, ])
by_hour
#> # A tibble: 18 × 3
#>   tour            hour fixtures
#>   <chr>          <int>    <int>
#> 1 challenger_men     9        2
#> 2 challenger_men    10        1
#> 3 wta               10        2
#> 4 atp               11        1
#> 5 challenger_men    11        1
#> 6 wta               11        1
#> # ℹ 12 more rows

by_hour has no rows when no fixture today has a start time yet. That happens before the order of play is out.

The hours are UTC. For local hours, pass your zone as tz in the format() call, for example tz = "Europe/London", and change the axis label to match.

Chart fixtures by tour and hour

Each tile is one tour in one hour, and the number on it is the count of fixtures that start then. Hours run down the page, so the chart stays readable on a narrow screen. The if skips the chart when there is nothing to count.

library(ggplot2)

if (nrow(by_hour) > 0) {
  ggplot(by_hour, aes(x = tour, y = hour, fill = fixtures)) +
    geom_tile(width = 0.94, height = 0.88) +
    geom_text(aes(label = fixtures), colour = "#1a1a19", size = 4) +
    scale_x_discrete(position = "top") +
    scale_y_reverse(breaks = 0:23, labels = function(h) sprintf("%02d:00", h)) +
    scale_fill_gradient(low = "#cde2fb", high = "#5598e7", guide = "none") +
    labs(
      title = "Fixtures by tour and hour",
      subtitle = format(today, "%d %B %Y"),
      x = NULL, y = "Start hour (UTC)"
    ) +
    theme_minimal(base_size = 13) +
    theme(panel.grid = element_blank(), plot.title.position = "plot")
}

Grid of fixture counts with one column for each tour and one row for each start hour in UTC. Each tile shows how many fixtures start in that hour on that tour.

See what is live now

live_matches() returns the matches in play, with the current score. Nested fields arrive as flat columns, such as players.p1.name. The result has no columns when nothing is in play, and no score.sets column when no row has a score yet. Picking with intersect() keeps the code safe in both cases.

live <- live_matches()

This output is also from a recorded response with made-up players.

wanted <- c("tour", "tournament", "players.p1.name", "players.p2.name", "score.sets")
live[, intersect(wanted, names(live))]
#> # A tibble: 3 × 5
#>   tour       tournament  players.p1.name players.p2.name score.sets
#>   <chr>      <chr>       <chr>           <chr>           <list>    
#> 1 challenger Stonebridge Tobin Varnholt  Emil Quenby     <int [2]> 
#> 2 challenger Stonebridge Marek Odrazil   Pascal Skerrow  <int [2]> 
#> 3 wta        Port Elm    Lena Tamsin-Roe Kira Ebbrey     <int [2]>

score.sets is a list column. Each entry holds the sets won by the first and the second player. Here tour uses the same values as the tour filter, so live_matches(tour = "wta") returns only the WTA rows.

Where to go next

  • The API reference lists every endpoint and field.
  • The pricing page shows what each plan opens.
  • The package README covers players, rankings, the results archive and error handling.