Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in plot_fastest error + format Introduction #108

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/plot_fastest.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ plot_fastest <- function(season = get_current_season(), round = 1, session = 'R'
lim_min <- min(min(driver_data$x, na.rm = T), min(driver_data$y, na.rm = T))
lim_max <- max(max(driver_data$x, na.rm = T), max(driver_data$y, na.rm = T))
if(color == 'gear'){
ggplot2::ggplot(driver_data, ggplot2::aes(.data$x, .data$y, color = as.factor(.data$n_gear), group = NA)) +
ggplot2::ggplot(driver_data, ggplot2::aes(.data$x, .data$y, color = as.factor(.data$n_gear), group = 1)) +
ggplot2::geom_path(linewidth = 4, lineend = 'round') +
ggplot2::scale_color_manual(name = 'Gear',
values = c("#BC3C29", "#0072B5", "#E18727", "#20854E", "#7876B1", "#6F99AD", "#FFDC91", "#EE4C97"),
Expand All @@ -78,7 +78,7 @@ plot_fastest <- function(season = get_current_season(), round = 1, session = 'R'
subtitle = glue::glue('{driver} Fastest Lap | {lap_time}',driver = driver, lap_time = lap_time),
caption = 'Generated by {f1dataR} package')
} else if(color == 'speed'){
ggplot2::ggplot(driver_data, ggplot2::aes(.data$x, .data$y, color = .data$speed, group = NA)) +
ggplot2::ggplot(driver_data, ggplot2::aes(.data$x, .data$y, color = .data$speed, group = 1)) +
ggplot2::geom_path(linewidth = 4, lineend = 'round') +
ggplot2::scale_color_gradient(low = 'white', high = 'red')+
theme_dark_f1() +
Expand Down
13 changes: 9 additions & 4 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ dir.create(file.path(getwd(), "vignettes","vig_build_tmp"), recursive = TRUE)
withr::local_options(f1dataR.cache = file.path(getwd(), "vignettes","vig_build_tmp"))
```

## Basics

f1dataR serves as a tool to get neatly organized Formula 1 data into your R environment. Here we will go over the basic functions to understand how the package works.



The most sought-after aspect of F1 data is telemetry data.
Let's get Leclerc's fastest lap from the first race of 2022:

```{r telem}
library(f1dataR)

Expand All @@ -36,7 +39,7 @@ load_driver_telemetry(2022, 1, driver = 'LEC', fastest_only = T)

Now let's use ggplot2 to visualize some of the data we have

```{r simple_plot}
```{r simple_plot, warning=FALSE, message=FALSE}
library(dplyr)
library(ggplot2)

Expand Down Expand Up @@ -65,7 +68,9 @@ ggplot(data, aes(distance, throttle, color = driver_code))+

```

Now lets visualize speed and use the f1 dark theme for ggplot included in the package
## Integrated plotting

There are a couple of functions in the package that help with plotting. The first one is `theme_dark_f1()` that simply applies a theme similar to the official F1 graphics. We can apply it to our previous data.

```{r use_theme}
ggplot(data, aes(distance, speed, color = driver_code))+
Expand All @@ -81,13 +86,13 @@ ggplot(data, aes(distance, speed, color = driver_code))+
```


We can also use one of the plotting functions included in the package.
Another built-in function is `plot_fastest()` that can plot the speed or gear changes throughout the fastest lap for a driver/race.

```{r use_builtin}
plot_fastest(2022, 1, 'R', 'PER')
```


## Combining several functions

Now let's look at a more complete analysis. We want to visualize how lap time change over time (tyre age) for Pérez with every compound used in the Spanish GP.

Expand Down