### Install f1dataR development version Source: https://scasanova.github.io/f1dataR/index.html Use these commands to install the development version from GitHub and load the library. ```R if (!require("remotes")) install.packages("remotes") remotes::install_github("SCasanova/f1dataR") library(f1dataR) ``` -------------------------------- ### get_tire_compounds examples Source: https://scasanova.github.io/f1dataR/reference/get_tire_compounds.html Interactive examples showing how to get tire compounds for the current season and for 2018. The code is wrapped in an if(interactive()) block. ```r if (interactive()) { # To get this season's tires get_tire_compounds() # Compare to 2018 tires: get_tire_compounds(2018) } ``` -------------------------------- ### Load required libraries Source: https://scasanova.github.io/f1dataR/articles/jolpica-data-analysis.html Initial setup to load the f1dataR and dplyr libraries for data analysis. ```R library(f1dataR) library(dplyr) ``` -------------------------------- ### Example: get_driver_style, get_driver_color_mapping, get_team_color Source: https://scasanova.github.io/f1dataR/reference/get_aesthetics.html Interactive example showing how to retrieve driver style for a specific race, current season style, driver color mapping, and team color. Requires an interactive R session. ```r if (interactive()) { # To get a specific season/race, specify them. get_driver_style(driver = "ALO", season = 2024, round = 3) # For drivers who haven't moved around recently, get their current season's style: get_driver_style(driver = "LEC") # Get all driver abbreviations and colors quickly: get_driver_color_mapping(season = 2023, round = "Montreal", session = "R") get_team_color(team = "Alpine", season = 2023, round = 1) } ``` -------------------------------- ### Load quali session from 2019 round 1 Source: https://scasanova.github.io/f1dataR/reference/load_race_session.html Example that loads the qualifying session from the 2019 first round. Only runs in interactive mode; the loaded session is assigned to `session` for later use. ```r # Load the quali session from 2019 first round if (interactive()) { session <- load_race_session(season = 2019, round = 1, session = "Q") } ``` -------------------------------- ### change_cache examples: custom directory and off Source: https://scasanova.github.io/f1dataR/reference/change_cache.html Example usage wrapped in a dontrun block. The first call sets a custom cache directory and creates it if needed. The second turns caching off for the session. ```r if (FALSE) { # \dontrun{ change_cache("~/f1dataRcache", create_dir = TRUE) change_cache("off", persist = FALSE) } # } ``` -------------------------------- ### Install f1dataR from CRAN Source: https://scasanova.github.io/f1dataR/index.html Use this command to install the stable version of the package from CRAN. ```R install.packages("f1dataR") ``` -------------------------------- ### Example: conditional call to clear_f1_cache() (dontrun) Source: https://scasanova.github.io/f1dataR/reference/clear_cache.html Example shown in the documentation, wrapped in `if (FALSE)` and `# \dontrun{}` to prevent execution during package checks. Call `clear_f1_cache()` to erase cached data. ```R if (FALSE) { # \dontrun{ clear_f1_cache() } # } ``` -------------------------------- ### Load lap times with load_laps Source: https://scasanova.github.io/f1dataR/index.html This example demonstrates loading lap-by-lap data for a specific season and round, including the resulting tibble output. ```R load_laps(season = 2021, round = 15) #> # A tibble: 1,025 × 6 #> driver_id position time lap time_sec season #> #> 1 sainz 1 1:42.997 1 103. 2021 #> 2 norris 2 1:44.272 1 104. 2021 #> 3 russell 3 1:46.318 1 106. 2021 #> 4 stroll 4 1:47.279 1 107. 2021 #> 5 ricciardo 5 1:48.221 1 108. 2021 #> 6 alonso 6 1:49.347 1 109. 2021 #> 7 hamilton 7 1:49.826 1 110. 2021 #> 8 perez 8 1:50.617 1 111. 2021 #> 9 ocon 9 1:51.098 1 111. 2021 #> 10 raikkonen 10 1:51.778 1 112. 2021 #> # ℹ 1,015 more rows ``` -------------------------------- ### get_fastf1_version() Source: https://scasanova.github.io/f1dataR/reference/get_fastf1_version.html Gets the current installed FastF1 version available (via `reticulate`) to the function. Displays a note if significantly out of date. ```APIDOC ## get_fastf1_version() ### Description Gets the current installed FastF1 version available (via `reticulate`) to the function. Displays a note if significantly out of date. ### Usage ```r get_fastf1_version() ``` ### Value version as class `package_version` ``` -------------------------------- ### Example: Load telemetry for HAM in Bahrain qualifying Source: https://scasanova.github.io/f1dataR/reference/load_driver_telemetry.html Example usage of load_driver_telemetry() to load the fastest lap telemetry for driver HAM in the 2023 Bahrain Grand Prix qualifying session. Wrapped in if (interactive()) to avoid running in non-interactive sessions. ```r if (interactive()) { telem <- load_driver_telemetry( season = 2023, round = "Bahrain", session = "Q", driver = "HAM", laps = "fastest" ) } ``` -------------------------------- ### Correct track ratio example with plot_fastest Source: https://scasanova.github.io/f1dataR/reference/correct_track_ratio.html Example usage of correct_track_ratio on a plot created by plot_fastest. The example is wrapped in a dontrun block, so it is not executed during package checks. It shows that plot_fastest plots are already ratio corrected, but correct_track_ratio can still be applied to adjust the ratio. ```r if (FALSE) { # \dontrun{ # Note that plot_fastest plots have already been ratio corrected fast_plot <- plot_fastest(season = 2022, round = 1, session = "Q", driver = V) correct_track_ratio(fast_plot) } # } ``` -------------------------------- ### Load telemetry and circuit data for Silverstone 2022 Source: https://scasanova.github.io/f1dataR/articles/plotting-turn-info.html Loads Verstappen's fastest qualifying lap telemetry and the Silverstone circuit details for the 2022 British Grand Prix. These data objects are used in the subsequent plotting examples. ```R ver <- load_driver_telemetry(season = 2022, round = "Silverstone", session = "Q", driver = "VER", laps = "fastest") silverstone_circuit <- load_circuit_details(season = 2022, round = "Silverstone") ``` -------------------------------- ### Plot average pit time per team at 2023 Azerbaijan GP Source: https://scasanova.github.io/f1dataR/articles/introduction.html Loads pit stop and results data for round 4 of 2023, joins them to get driver-team combos, and computes average pit time per constructor. Uses get_team_color() and get_team_name() for plot styling; pit time is entry-to-exit difference, not stopped time. ```R pit_data <- load_pitstops(2023, 4) driver_team <- load_results(2023, 4) %>% select(driver_id, constructor_id) pit_constructor <- pit_data %>% left_join(driver_team, by = "driver_id") %>% group_by(constructor_id) %>% summarise(pit_time = mean(as.numeric(duration))) pit_constructor$constructor_color <- sapply(pit_constructor$constructor_id, get_team_color, season = 2023, round = 4, USE.NAMES = FALSE) pit_constructor$team_name <- sapply(pit_constructor$constructor_id, get_team_name, season = 2023, short = TRUE, USE.NAMES = FALSE) ggplot(pit_constructor, aes(x = team_name, y = pit_time, fill = team_name)) + geom_bar(stat = "identity", fill = pit_constructor$constructor_color) + theme_dark_f1(axis_marks = TRUE) + theme( legend.position = "none" ) + labs( x = "Constructor", y = "Average Pit Time (seconds)" ) + ggtitle("Average time in pit lane for each team", subtitle = "Azerbaijan Grand Prix 2023") ``` -------------------------------- ### Load Required Libraries Source: https://scasanova.github.io/f1dataR/articles/plotting-turn-info.html Initializes the environment with f1dataR, dplyr, and ggplot2. ```R library(f1dataR) library(dplyr) library(ggplot2) ``` -------------------------------- ### Load f1dataR package Source: https://scasanova.github.io/f1dataR/articles/alonso-penalty-2024.html Initializes the f1dataR package for data access. ```R library(f1dataR) ``` -------------------------------- ### load_circuits(season = get_current_season()) Source: https://scasanova.github.io/f1dataR/reference/load_circuits.html Loads circuit info for all circuits in a given season. Use `.load_circuits()` for an uncached version of this function. ```APIDOC ## load_circuits(season = get_current_season()) ### Description Loads circuit info for all circuits in a given season. Use `.load_circuits()` for an uncached version of this function. ### Usage ```r load_circuits(season = get_current_season()) ``` ### Arguments - **season** (number) - Optional - number from 1950 to current season (defaults to current season). ### Value A tibble with one row per circuit. ``` -------------------------------- ### Plot Verstappen's fastest lap Source: https://scasanova.github.io/f1dataR/reference/plot_fastest.html Example usage of plot_fastest to visualize Max Verstappen's fastest lap from the 2023 Bahrain Grand Prix using speed as the color variable. ```R # Plot Verstappen's fastest lap (speed) from Bahrain 2023: if (interactive()) { plot_fastest(2023, 1, "R", "VER", "speed") } ``` -------------------------------- ### Set cache directory with options Source: https://scasanova.github.io/f1dataR/index.html Manually sets the cache directory for session data using the f1dataR.cache option. ```R options(f1dataR.cache = "path/to/directory") ``` -------------------------------- ### Load session laps for Pérez in 2023 Spanish GP Source: https://scasanova.github.io/f1dataR/articles/introduction.html Loads session laps for the 2023 Spanish Grand Prix, filters for Pérez, and groups by tyre compound. This is the start of a more complete analysis on lap time vs tyre age. ```R laps <- load_session_laps(2023, "Spain") %>% filter(driver == "PER") %>% group_by(compound) %>% ``` -------------------------------- ### Prepare Telemetry Data Source: https://scasanova.github.io/f1dataR/articles/plotting-turn-info.html Loads telemetry for specific drivers and prepares a combined dataset with driver colors. ```R lec <- load_driver_telemetry(2022, 1, "Q", driver = "LEC", laps = "fastest") ham <- load_driver_telemetry(2022, 1, "Q", driver = "HAM", laps = "fastest") per <- load_driver_telemetry(2022, 1, "Q", driver = "PER", laps = "fastest") telem <- bind_rows(lec, ham, per) %>% select(rpm, speed, n_gear, throttle, brake, drs, distance, time, driver_code) %>% mutate(drs = ifelse(drs == 12, 1, 0)) drivercolours <- c( "LEC" = get_driver_color("LEC", 2022, 1), "HAM" = get_driver_color("HAM", 2022, 1), "PER" = get_driver_color("PER", 2022, 1) ) ``` -------------------------------- ### Load ggplot2 library Source: https://scasanova.github.io/f1dataR/articles/jolpica-data-analysis.html Load the ggplot2 library for visualizing grid to finish position correlation. ```R library(ggplot2) ``` -------------------------------- ### change_cache(cache = "memory", create_dir = FALSE, persist = FALSE) Source: https://scasanova.github.io/f1dataR/reference/change_cache.html Changes the caching settings for the package. The cache can be set to memory, filesystem, off, or a custom directory, with options to persist across sessions. ```APIDOC ## change_cache(cache = "memory", create_dir = FALSE, persist = FALSE) ### Description Changes the caching settings for the package. By default, the cache is set to keep results in memory to reduce requests to online services. The cache can be set to a file directory to persist between sessions, or turned off for testing or waiting for data updates. ### Usage ```r change_cache(cache = "memory", create_dir = FALSE, persist = FALSE) ``` ### Arguments - **cache** (character) - Required - One of `'memory'`, `'filesystem'`, `'off'`, or a directory path. If `'filesystem'`, the package writes the cache to the operating system's default location for permanent or temporary caches (see `persist`). - **create_dir** (logical) - Optional - Whether to create the directory if it doesn't already exist when a path cache directory is provided. Defaults to `FALSE`, but always happens if `cache` is set to `'filesystem'`. - **persist** (logical) - Optional - Whether to make the change permanent (`TRUE`) or temporary (default `FALSE`). If `cache` is set to `'off'` and `persist` is `TRUE`, the existing cache is cleared by calling `clear_cache()`. If `filesystem` is chosen and `persist` is `TRUE`, a cache directory is placed in the default OS location; if `FALSE`, a temporary directory is used and removed at the end of the session. ### Value No return value; called for side effects. ### Examples ```r if (FALSE) { # \dontrun{ change_cache("~/f1dataRcache", create_dir = TRUE) change_cache("off", persist = FALSE) } # } ``` ``` -------------------------------- ### get_drivers_by_team Source: https://scasanova.github.io/f1dataR/reference/driver_team_lookup.html Looks up a team's drivers for the provided race session (season, round, session). If looking for practice rookies, they typically participate in `session = FP1`. ```APIDOC ## get_drivers_by_team ### Description Looks up a team's drivers for the provided race session (season, round, session). If looking for practice rookies, they typically participate in `session = FP1`. ### Usage ```r get_drivers_by_team( team_name, season = get_current_season(), round = 1, session = "R" ) ``` ### Arguments - **team_name** (character) - Required - The team name (as a string) to use for lookup. - **season** (numeric) - Optional - The season for which the look-up should occur. Should be a number from 2018 to current season. Defaults to current season. - **round** (numeric) - Optional - Number from 1 to 24 (depending on season selected) and defaults to most recent. Also accepts race name. - **session** (character) - Optional - The code for the session to load. Options are `'FP1'`, `'FP2'`, `'FP3'`, `'Q'`, `'S'`, `'SS'`, `'SQ'`, and `'R'`. Default is `'R'`, which refers to Race. ### Value An unnamed character vector with all drivers for the requested team. ``` -------------------------------- ### Load Session Laps Source: https://scasanova.github.io/f1dataR/index.html Retrieves detailed lap and sector times, tyre information, and optional weather data for a Grand Prix session. ```R load_session_laps(season = 2023, round = 4, add_weather = TRUE) #> # A tibble: 962 × 39 #> time driver driver_number lap_time lap_number stint pit_out_time pit_in_time #> #> 1 3892. VER 1 110. 1 1 NaN NaN #> 2 4000. VER 1 108. 2 1 NaN NaN #> 3 4108. VER 1 108. 3 1 NaN NaN #> 4 4215. VER 1 107. 4 1 NaN NaN #> 5 4322. VER 1 107. 5 1 NaN NaN #> 6 4430. VER 1 107. 6 1 NaN NaN #> 7 4537. VER 1 107. 7 1 NaN NaN #> 8 4643. VER 1 107. 8 1 NaN NaN #> 9 4750. VER 1 107. 9 1 NaN NaN #> 10 4861. VER 1 111. 10 1 NaN 4860. #> # ℹ 952 more rows #> # ℹ 31 more variables: sector1time , sector2time , sector3time , #> # sector1session_time , sector2session_time , #> # sector3session_time , speed_i1 , speed_i2 , speed_fl , #> # speed_st , … ``` -------------------------------- ### load_circuit_details() function usage Source: https://scasanova.github.io/f1dataR/reference/load_circuit_details.html Loads circuit details for a specific race session. Defaults to the current season and round 1. The log_level argument controls FastF1 logging detail. ```r load_circuit_details( season = get_current_season(), round = 1, log_level = "WARNING" ) ``` -------------------------------- ### change_cache function signature Source: https://scasanova.github.io/f1dataR/reference/change_cache.html The usage signature for change_cache(). It takes cache (one of 'memory', 'filesystem', 'off', or a directory), create_dir (whether to create the directory if it doesn't exist), and persist (whether to make the change permanent). ```r change_cache(cache = "memory", create_dir = FALSE, persist = FALSE) ``` -------------------------------- ### Usage: get_driver_style, get_driver_color, get_team_color, get_driver_color_map Source: https://scasanova.github.io/f1dataR/reference/get_aesthetics.html Function signatures for retrieving driver/team styles and colors. Defaults to current season and round 1, with session default 'R' for mapping functions. ```r get_driver_style(driver, season = get_current_season(), round = 1) get_driver_color(driver, season = get_current_season(), round = 1) get_driver_colour(driver, season = get_current_season(), round = 1) get_team_color(team, season = get_current_season(), round = 1) get_team_colour(team, season = get_current_season(), round = 1) get_driver_color_map(season = get_current_season(), round = 1, session = "R") get_driver_colour_map(season = get_current_season(), round = 1, session = "R") ``` -------------------------------- ### load_circuit_details Source: https://scasanova.github.io/f1dataR/reference/load_circuit_details.html Loads circuit details for a specific race session. Useful for visualizing or annotating data. Contains information on corners, marshal_lights and marshal_sectors. ```APIDOC ## load_circuit_details ### Description Loads circuit details for a specific race session. Useful for visualizing or annotating data. Contains information on corners, marshal_lights and marshal_sectors. ### Usage ```r load_circuit_details( season = get_current_season(), round = 1, log_level = "WARNING" ) ``` ### Arguments - **season** (numeric) - Optional - Number from 2018 to current season. Defaults to current season. - **round** (numeric) - Optional - Number from 1 to 23 (depending on season selected). Also accepts race name. - **log_level** (character) - Optional - Detail of logging from fastf1 to be displayed. Choice of: `'DEBUG'`, `'INFO'`, `'WARNING'`, `'ERROR'` and `'CRITICAL'`. ### Value A list of tibbles containing corner number, marshall post number, or marshall segment, plus a numeric value for rotational offset of the data compared to telemetry data. The tibbles all have the following structure: `x` and `y` specify the position on the track map, `number` is the number of the corner, `letter` is optionally used to differentiate corners with the same number on some circuits, `angle` is an angle in degrees, used to visually offset the marker's placement on a track map in a logical direction, `distance` is the location of the marker as a distance from the start/finish line. ``` -------------------------------- ### Function usage: load_driver_telemetry() Source: https://scasanova.github.io/f1dataR/reference/load_driver_telemetry.html Shows the function signature with all parameters and their defaults. The function loads telemetry data for a driver, with options for season, round, session, driver, laps, and log level. Deprecated arguments race and fastest_only are included for backward compatibility. ```r load_driver_telemetry( season = get_current_season(), round = 1, session = "R", driver, laps = "fastest", log_level = "WARNING", race = lifecycle::deprecated(), fastest_only = lifecycle::deprecated() ) ``` -------------------------------- ### Build driver style data frame Source: https://scasanova.github.io/f1dataR/articles/jolpica-data-analysis.html Creates a data frame of driver styles (color, marker, linestyle, abbreviation) for the 2021 season, handling Kubica's mid-season team change. ```R driver_style <- rbind( get_session_drivers_and_teams(2021, round = 1), get_session_drivers_and_teams(2021, round = 13) ) %>% unique() driver_style$linestyle <- driver_style$marker <- driver_style$color <- driver_style$abbreviation <- NA for (i in seq_along(driver_style$name)) { if (driver_style$name[i] == "Robert Kubica") { # Manually handling Kubica style <- get_driver_style(driver_style$name[i], season = 2021, round = 13) driver_style$color[i] <- style$color driver_style$marker[i] <- 2 driver_style$linestyle[i] <- "dotted" driver_style$abbreviation[i] <- style$abbreviation } else { style <- get_driver_style(driver_style$name[i], season = 2021, round = 1) driver_style$color[i] <- style$color driver_style$marker[i] <- style$marker driver_style$linestyle[i] <- style$linestyle driver_style$abbreviation[i] <- style$abbreviation } } color_values <- driver_style$color names(color_values) <- driver_style$abbreviation marker_values <- driver_style$marker names(marker_values) <- driver_style$abbreviation linestyle_values <- driver_style$linestyle names(linestyle_values) <- driver_style$abbreviation points <- dplyr::left_join(points, load_drivers(2021)[, c("driver_id", "code")], by = "driver_id") ``` -------------------------------- ### Create violin plot of driver lap times with load_laps and ggplot2 Source: https://scasanova.github.io/f1dataR/articles/jolpica-data-analysis.html Loads lap data, filters to racing laps (under 100 seconds), computes each driver's average lap time, and creates a violin plot with boxplots. The drivers are ordered by average lap time and colored using the recycled color values. ```R laps <- load_laps(season = 2021, round = 4) %>% filter(time_sec < 100) %>% group_by(driver_id) %>% mutate(driver_avg = mean(time_sec)) %>% ungroup() %>% left_join(load_drivers(2021)[, c("driver_id", "code")], by = "driver_id") %>% mutate(code = factor(code, unique(code[order(driver_avg)]))) ggplot(laps, aes(x = code, y = time_sec, color = code, fill = code)) + geom_violin(trim = FALSE) + scale_color_manual("Driver", values = color_values, aesthetics = c("color", "fill")) + geom_boxplot(width = 0.1, color = "black", fill = "white", outlier.shape = NA) + theme_dark_f1(axis_marks = TRUE) + ggtitle("Driver Lap Times", subtitle = paste("Racing Laps Only -", racename)) + xlab("Driver ID") + ylab("Lap Time (s)") + theme(axis.text.x = element_text(angle = 90), legend.position = "") ``` -------------------------------- ### Visualize telemetry with ggplot2 Source: https://scasanova.github.io/f1dataR/articles/introduction.html Loads Leclerc's fastest lap telemetry, takes the first 300 rows, and plots throttle percentage against distance using ggplot2. Requires dplyr and ggplot2 packages. ```R library(dplyr) library(ggplot2) lec <- load_driver_telemetry(2022, 1, "Q", driver = "LEC", laps = "fastest") %>% head(300) ggplot(lec, aes(distance, throttle)) + geom_line() + theme_minimal() ``` -------------------------------- ### get_tire_compounds(season = get_current_season()) Source: https://scasanova.github.io/f1dataR/reference/get_tire_compounds.html Returns a data.frame of all tire compound names and associated colours for a specified season. The season argument defaults to the current season. ```APIDOC ## get_tire_compounds(season = get_current_season()) ### Description Returns a data.frame of all tire compound names and associated colours for a season. ### Usage ```r get_tire_compounds(season = get_current_season()) ``` ### Arguments - **season** (number) - Optional - Number from 2018 to current season. Defaults to current season. ### Value A data.frame with two columns: `compound` and `color`. ### Examples ```r if (interactive()) { # To get this season's tires get_tire_compounds() # Compare to 2018 tires: get_tire_compounds(2018) } ``` ``` -------------------------------- ### get_driver_telemetry() Source: https://scasanova.github.io/f1dataR/reference/get_driver_telemetry.html Loads telemetry data for a selected driver and session. Returns a tibble with telemetry data. ```APIDOC ## get_driver_telemetry() ### Description Loads telemetry data for a selected driver and session. Returns a tibble with telemetry data. ### Usage ```r get_driver_telemetry( season = get_current_season(), round = 1, session = "R", driver, laps = "fastest", log_level = "WARNING", fastest_only = lifecycle::deprecated(), race = lifecycle::deprecated() ) ``` ### Arguments - **season** (number) - Required - Number from 2018 to current season (defaults to current season). - **round** (number) - Required - Number from 1 to 23 (depending on season selected). Also accepts race name. - **session** (character) - Required - The code for the session to load. Options are `'FP1'`, `'FP2'`, `'FP3'`, `'Q'`, `'S'`, `'SS'`, `'SQ'`, and `'R'`. Default is `'R'`, which refers to Race. - **driver** (character) - Required - Three letter driver code (see `load_drivers()` for a list). - **laps** (character or integer) - Required - Which lap's telemetry to return. One of an integer lap number (<= total laps in the race), `fastest`, or `all`. Note that integer lap choice requires `fastf1` version 3.0 or greater. - **log_level** (character) - Required - Detail of logging from fastf1 to be displayed. Choice of: `'DEBUG'`, `'INFO'`, `'WARNING'`, `'ERROR'` and `'CRITICAL'`. See fastf1 documentation. - **fastest_only** (deprecated) - Optional - `fastest_only` is no longer supported, indicated preferred laps in `laps`. - **race** (deprecated) - Optional - `race` is no longer supported, use `round`. ### Value A tibble with telemetry data for selected driver/session. ``` -------------------------------- ### Load and Process F1 Qualifying Data Source: https://scasanova.github.io/f1dataR/articles/jolpica-data-analysis.html Loads qualifying data and schedule information, calculates time differences relative to the fastest lap, and prepares the data for visualization. ```R # Load the Data quali <- load_quali(2021, 8) # Get Grand Prix Name racename <- load_schedule(2021) %>% filter(round == 8) %>% pull("race_name") # Process the Data quali <- quali %>% summarize(t_min = min(q1_sec, q2_sec, q3_sec, na.rm = TRUE), .by = driver_id) %>% mutate(t_diff = t_min - min(t_min)) %>% left_join(load_drivers(2021)[, c("driver_id", "code")], by = "driver_id") %>% mutate(code = factor(code, unique(code[order(-t_min)]))) ``` -------------------------------- ### Plot gear usage with corner labels on track Source: https://scasanova.github.io/f1dataR/articles/plotting-turn-info.html Creates a gear-usage track plot for Verstappen's fastest qualifying lap and adds corner labels directly on the track. Uses `theme_dark_f1()` and `correct_track_ratio()` to style and correct the track aspect ratio. ```R gear_plot <- ggplot(ver, aes(x, y, color = as.factor(n_gear), group = NA)) + geom_path(linewidth = 4, lineend = "round") + ggplot2::scale_color_manual( name = "Gear", values = c( "1" = "#BC3C29", "2" = "#0072B5", "3" = "#E18727", "4" = "#20854E", "5" = "#7876B1", "6" = "#6F99AD", "7" = "#FFDC91", "8" = "#EE4C97" ), aesthetics = c("color", "fill") ) + theme_dark_f1() + labs( title = "British Grand Prix 2022", subtitle = "Gear in use by Verstappen in Quali", color = "Gear" ) labelled_gear_plot <- gear_plot + geom_label(data = silverstone_circuit$corners, aes( label = paste0(number, letter), y = y, x = x, color = "#9A9A9A" ), show.legend = FALSE) correct_track_ratio(labelled_gear_plot) ``` -------------------------------- ### Calculate offset label positions using corner angle Source: https://scasanova.github.io/f1dataR/articles/plotting-turn-info.html Defines helper functions to offset corner labels using the `angle` column from `get_circuit_data()`. Computes new label coordinates (`labx`, `laby`) for the Silverstone corners, with a default distance of 750. ```R labelx <- function(x, angle, distance = 750) { angle <- angle * pi / 180 return(cos(angle) * distance + x) } labely <- function(y, angle, distance = 750) { angle <- angle * pi / 180 return(sin(angle) * distance + y) } silverstone_circuit$corners$labx <- labelx(silverstone_circuit$corners$x, silverstone_circuit$corners$angle) silverstone_circuit$corners$laby <- labely(silverstone_circuit$corners$y, silverstone_circuit$corners$angle) ``` -------------------------------- ### get_driver_color_map(season = get_current_season(), round = 1, session = "R") Source: https://scasanova.github.io/f1dataR/reference/get_aesthetics.html Returns a data.frame of driver short-codes and their hexadecimal colour. ```APIDOC ## get_driver_color_map(season = get_current_season(), round = 1, session = "R") ### Description Returns a data.frame of driver short-codes and their hexadecimal colour. Both drivers on a team will get the same colour returned. Data is provided by the python FastF1 package. Requires provision of a specific race event (season/round/session). ### Usage ```r get_driver_color_map(season = get_current_season(), round = 1, session = "R") ``` ### Arguments - **season** (numeric) - Optional - A season corresponding to the race being referenced for collecting colour/style. Should be a number from 2018 to current season. Defaults to current season. - **round** (numeric/character) - Optional - A round corresponding to the race being referenced for collecting colour/style. Should be a string name or a number from 1 to the number of rounds in the season and defaults to 1. - **session** (character) - Optional - The code for the session to load. Options are `'FP1'`, `'FP2'`, `'FP3'`, `'Q'`, `'S'`, `'SS'`,`'SQ'`, and `'R'`. Default is `'R'`, which refers to Race. ### Value A data.frame of driver short-codes and their hexadecimal colour. ### Examples ```r if (interactive()) { get_driver_color_map(season = 2023, round = "Montreal", session = "R") } ``` ``` -------------------------------- ### Clear f1dataR cache with clear_f1_cache() Source: https://scasanova.github.io/f1dataR/reference/clear_cache.html Clears the f1dataR cache. The cache directory can be set via `option(f1dataR.cache = [cache dir])`, but defaults to a temporary directory. Returns no value. ```R clear_f1_cache() ``` -------------------------------- ### load_race_session() function signature Source: https://scasanova.github.io/f1dataR/reference/load_race_session.html Function signature for loading session data from the official F1 data stream via the fastf1 Python library. Use this to see the default arguments and the deprecated `race` parameter. ```r load_race_session( obj_name = "session", season = get_current_season(), round = 1, session = "R", log_level = "WARNING", race = lifecycle::deprecated() ) ``` -------------------------------- ### get_session_drivers_and_teams Source: https://scasanova.github.io/f1dataR/reference/driver_team_lookup.html Returns a data frame of all drivers and their team for a provided session. ```APIDOC ## get_session_drivers_and_teams ### Description Returns a data frame of all drivers and their team for a provided session. ### Usage ```r get_session_drivers_and_teams(season, round, session = "R") ``` ### Arguments - **season** (numeric) - Required - The season for which the look-up should occur. Should be a number from 2018 to current season. Defaults to current season. - **round** (numeric) - Required - Number from 1 to 24 (depending on season selected) and defaults to most recent. Also accepts race name. - **session** (character) - Optional - The code for the session to load. Options are `'FP1'`, `'FP2'`, `'FP3'`, `'Q'`, `'S'`, `'SS'`, `'SQ'`, and `'R'`. Default is `'R'`, which refers to Race. ### Value A data.frame of all drivers and their team for the provided session. ``` -------------------------------- ### load_session_laps function usage Source: https://scasanova.github.io/f1dataR/reference/load_session_laps.html The usage signature for the load_session_laps function. It shows the function arguments with defaults, including season, round, session, log_level, add_weather, and the deprecated race argument. ```r load_session_laps( season = get_current_season(), round = 1, session = "R", log_level = "WARNING", add_weather = FALSE, race = lifecycle::deprecated() ) ``` -------------------------------- ### Compare multiple drivers' telemetry Source: https://scasanova.github.io/f1dataR/articles/introduction.html Loads telemetry for Leclerc, Hamilton, and Pérez from the 2022 Bahrain Qualifying, combines them with bind_rows(), and plots throttle by distance colored by driver code. ```R ham <- load_driver_telemetry(2022, 1, "Q", driver = "HAM", laps = "fastest") %>% head(300) per <- load_driver_telemetry(2022, 1, "Q", driver = "PER", laps = "fastest") %>% head(300) data <- bind_rows(lec, ham, per) ggplot(data, aes(distance, throttle, color = driver_code)) + geom_line() + theme_minimal() ``` -------------------------------- ### Visualize Qualifying Time Comparison Source: https://scasanova.github.io/f1dataR/articles/jolpica-data-analysis.html Creates a horizontal bar chart showing the gap to pole position for each driver using ggplot2. ```R # Plot the results ggplot(quali, aes(x = code, y = t_diff, color = code, fill = code)) + geom_col() + coord_flip() + ggtitle(paste0(racename, " 2021 Quali Time Comparison"), subtitle = paste("VER Pole time:", min(quali$t_min), "s") ) + scale_color_manual(values = color_values, aesthetics = c("fill", "color")) + ylab("Gap to Pole (s)") + theme_dark_f1(axis_marks = TRUE) + theme(legend.position = "") ``` -------------------------------- ### Retrieve Circuit Corner Data Source: https://scasanova.github.io/f1dataR/articles/plotting-turn-info.html Fetches circuit details and extracts corner information for plotting. ```R bahrain_circuit <- load_circuit_details(2022, 1) bahrain_corners <- bahrain_circuit$corners speedmax <- max(telem$speed, na.rm = TRUE) speedmin <- min(telem$speed, na.rm = TRUE) ``` -------------------------------- ### get_driver_colour_map(season = get_current_season(), round = 1, session = "R") Source: https://scasanova.github.io/f1dataR/reference/get_aesthetics.html Alias for `get_driver_color_map()`. Returns a data.frame of driver short-codes and their hexadecimal colour. ```APIDOC ## get_driver_colour_map(season = get_current_season(), round = 1, session = "R") ### Description Alias for `get_driver_color_map()`. Returns a data.frame of driver short-codes and their hexadecimal colour. Data is provided by the python FastF1 package. ### Usage ```r get_driver_colour_map(season = get_current_season(), round = 1, session = "R") ``` ### Arguments - **season** (numeric) - Optional - A season corresponding to the race being referenced for collecting colour/style. Should be a number from 2018 to current season. Defaults to current season. - **round** (numeric/character) - Optional - A round corresponding to the race being referenced for collecting colour/style. Should be a string name or a number from 1 to the number of rounds in the season and defaults to 1. - **session** (character) - Optional - The code for the session to load. Options are `'FP1'`, `'FP2'`, `'FP3'`, `'Q'`, `'S'`, `'SS'`,`'SQ'`, and `'R'`. Default is `'R'`, which refers to Race. ### Value A data.frame of driver short-codes and their hexadecimal colour. ### Examples ```r if (interactive()) { get_driver_colour_map(season = 2023, round = "Montreal", session = "R") } ``` ``` -------------------------------- ### Plot fastest lap with plot_fastest() Source: https://scasanova.github.io/f1dataR/articles/introduction.html Plots the fastest lap for Pérez in the 2022 Bahrain Grand Prix race, showing gear changes. The function may take a minute if the session hasn't been loaded yet. ```R plot_fastest(2022, 1, "R", "PER") ``` -------------------------------- ### load_results Source: https://scasanova.github.io/f1dataR/reference/load_results.html Loads final race results for a given year and round. Use `.load_results()` for an uncached version. ```APIDOC ## load_results(season = get_current_season(), round = "last") ### Description Loads final race results for a given year and round. Use `.load_results()` for an uncached version. ### Usage ```r load_results(season = get_current_season(), round = "last") ``` ### Arguments - **season** (number or character) - Optional - Number from 1950 to current season (or the word 'current') (defaults to current season). - **round** (number or character) - Optional - Number from 1 to 23 (depending on season), and defaults to most recent. Also accepts 'last'. ### Value A tibble with one row per driver, with columns for driver & constructor ID, the points won by each driver in the race, their finishing position, their starting (grid) position, number of completed laps, status code, gap to leader (or time of race), fastest lap ranking, drivers' fastest lap time, top speed achieved, and fastest lap time in seconds. ``` -------------------------------- ### Alias clear_cache() to clear f1dataR cache Source: https://scasanova.github.io/f1dataR/reference/clear_cache.html Alias for `clear_f1_cache()`, providing the same functionality of clearing the cache. No return value. ```R clear_cache() ``` -------------------------------- ### Load Driver Telemetry Source: https://scasanova.github.io/f1dataR/index.html Retrieves telemetry data for a specific driver. The first call to a session may take longer to load. ```R load_driver_telemetry(season = 2022, round = 4, driver = "PER") #> # A tibble: 592 × 19 #> date session_time time rpm speed n_gear throttle brake #> #> 1 2022-04-24 14:19:27 8308. 0 11221 282 7 100 FALSE #> 2 2022-04-24 14:19:27 8308. 0.021 11221 283 7 100 FALSE #> 3 2022-04-24 14:19:28 8308. 0.278 11221 284 7 100 FALSE #> 4 2022-04-24 14:19:28 8308. 0.401 11279 285 7 100 FALSE #> 5 2022-04-24 14:19:28 8309. 0.678 11337 286 7 100 FALSE #> 6 2022-04-24 14:19:28 8309. 0.681 11376 287 7 100 FALSE #> 7 2022-04-24 14:19:28 8309. 0.86 11416 288 7 100 FALSE #> 8 2022-04-24 14:19:29 8309. 1.08 11456 289 7 100 FALSE #> 9 2022-04-24 14:19:29 8309. 1.18 11461 289 7 100 FALSE #> 10 2022-04-24 14:19:29 8309. 1.24 11467 290 7 100 FALSE #> # ℹ 582 more rows #> # ℹ 11 more variables: drs , source , relative_distance , #> # status , x , y , z , distance , #> # driver_ahead , distance_to_driver_ahead , … ``` ```R load_driver_telemetry(season = 2018, round = 7, "Q", "HAM", laps = "fastest") #> # A tibble: 534 × 19 #> date session_time time rpm speed n_gear throttle brake #> #> 1 2018-06-09 18:59:18 3788. 0 10674 297 8 100 FALSE #> 2 2018-06-09 18:59:18 3788. 0.016 10704 298 8 100 FALSE #> 3 2018-06-09 18:59:18 3788. 0.043 10762 299 8 100 FALSE #> 4 2018-06-09 18:59:19 3788. 0.256 10820 301 8 100 FALSE #> 5 2018-06-09 18:59:19 3788. 0.343 10847 302 8 100 FALSE #> 6 2018-06-09 18:59:19 3788. 0.496 10875 303 8 100 FALSE #> 7 2018-06-09 18:59:19 3789. 0.643 10921 303 8 100 FALSE #> 8 2018-06-09 18:59:19 3789. 0.736 10967 304 8 100 FALSE #> 9 2018-06-09 18:59:19 3789. 0.943 10990 305 8 100 FALSE #> 10 2018-06-09 18:59:19 3789. 0.976 11014 306 8 100 FALSE #> # ℹ 524 more rows #> # ℹ 11 more variables: drs , source , relative_distance , #> # status , x , y , z , distance , #> # driver_ahead , distance_to_driver_ahead , … ``` -------------------------------- ### BibTeX citation for f1dataR Source: https://scasanova.github.io/f1dataR/authors.html BibTeX entry for citing the f1dataR package. Use this in LaTeX documents to reference the package. ```bibtex @Manual{, title = {f1dataR: Access Formula 1 Data}, author = {Santiago Casanova and Philip Bulsink}, year = {2026}, note = {R package version 2.0.2}, url = {https://scasanova.github.io/f1dataR/}, } ```