F1 graphs

Summer silly season! 

It's summer break for F1 and I wanted to take a look at how the season has progressed so far! Making these graphs was a lot of fun - I used new (to me) packages, and challenged myself with making them interactive and also embedded into this page. It definitely was not easy but I am pretty happy with how they turned out

This year has been a pretty exciting one for F1 races with over 7 different race winners across the 13 races that we have had so far this season. Verstappen and Redbull were expected to dominate the season, and as you can see below, it started off that way. They have maintained a lead in the constructors championships points, but, that gap is starting to close. Close competitors include Ferrari, who quickly demonstrated their ability to compete with Redbull but lost that edge through upgrades during the season. McLaren has had pace throughout the season with good results from both drivers, and they have been the most consistent competitor with Verstappen during the later portion of this first half of the season. Finally, Mercedes had a slow and dissapointing start but they seem to have found their place, and have quickly made up points in the championship battle. Notably - they have 3 P1s.

constructors_championship_points_totals

In the graph below you can see how each team did race to race. Mclaren has brought in a steady about of points each race, with some peaks in their plot, including when Piastri won at Hungary. Redbull has had ups and downs, and notable after Miami, they have not been able to bring is any many points each race. Ferrari has also had some dramatic ups and downs, with their most recent races not bringing in a large amount of points.

constructors_championship_points_individual

This is a monster of a graphic but I thought it would be fun to compare how each teammate does compared to the other from race to race. I didn't include Sauber because.. well.. it would have been an empty chart as of now (they haven't scored yet this season). Looking at McLaren, both Piastri and Norris have been high scorers throughout the season, with both of them scoring higher and higher as upgrades have brought them a faster car. Looking at Redbull, Verstappen continues to bring in points despite being unhappy about his car's performance recently. Notably, Perez has only brought in a small amount of points over the past 7 races, with 0 points for 3 of them.

combined_plot_bar

A little less informative, but much easier to look at, we can see which team members have contributed the most points to their teams. Again, Sauber not included because they have no points. I was pretty surprised to see that Gasly has brought in more points than Ocon for Alpine! He had 2 DNFs recently that were out of his control, and Ocon had a stronger start to the season but I guess somewhere in between all of that he did pile up some points! Tsunoda is outperforming Ricardo at Visa Cash App RB. For Aston Martin, Stroll has contributed a good amount of points this season as well.

combined_plot_pie

Finally, you can see which drivers contributed the most to overall points scored for the season. Most of the pie chart is made up of Ferrari, McLaren, Mercedes, and Red Bull!

2024_donut_totals

Okay, now let's dig into how I made these graphs! 

Getting Started

I use R studio a bit for work but this was the most intensive graph-related project that I have done so far. When thinking about what graphs I think will be compelling to display certain types of data, I like to refer to The R Graph Gallery. They provide a visual representation of a graph and categorize graphs into data types. From the start, I felt that parts of a whole, evolution, and ranking plots would be best suited to show how the season was progressing. The R Graph Gallery also has vignettes of code to achieve desired graph styles. This was a great place to start to remind myself of what packages I would need and how I would need to format my data.

Make it pretty

I wanted the graphs to be in theme with actual F1 content. For me, the F1 font is a key branding asset so I wanted to incorporate that into the titles of my graphs. I had to download an F1 font package and ensure that it was incorporated into the fonts I have available to me in R using font_add.

Next, I wanted to make sure that the colors on the graph stood out and were associated with teams and drivers. For this, I used the scale_color_manual function to assign colors to drivers and teams. Lots of teams have variations of blue so I had to switch some teams up to colors that they were less well known for, such as Red Bull having gold colors rather than blue or red.

Finally, I used a darker aesthetic for the background of the final images. I thought it made the colors and the graphs pop more!

Make it Fun!

After making a few static graphs, I wanted to challenge myself by making interactive graphs. I found that the plotly package interfaces with the ggplot package nicely in R studio for developing graphs and utilized plotly to both make the graphs interactive as well as house the graphs.

Repeat for all!

After getting the interactive graphs to work for a single constructor, I wanted to apply it to all of the constructors and design cohesive and organized outputs. Referencing just a single set of data is a lot easier than parsing and referencing data across 10 teams and 21 individuals. First, with the help of ChatGPT, I developed functions that would help me to apply the same parameters and themes to all of the different teams. It became quite complex to ensure that the names and the colors associated with those drivers were properly being linked to one another. I also found that ggplotly did not recognize all of the colors that I had previously used in just static graphs - sometimes there were even difficulties in referencing a color between a bar graph and a pie chart which involved a lot of adjustments to the theme that I had already laid out for my first set of graphs. After the functions were made, I used the subplot function to organize the layout of the final figure with the graphs that I wanted incorporated. The final figure had different themes outlined for it.

Packages Used:

ggplot2

dplyr

plotly

tidyr

htmlwidgets

Data:

Drivers standings: https://www.espn.com/f1/standings

Constructors: https://www.planetf1.com/standings

Fonts:

https://www.formula1.com/etc/designs/fom-website/fonts/F1Regular/Formula1-Regular.ttf

https://www.formula1.com/etc/designs/fom-website/fonts/F1Bold/Formula1-Bold.ttf

https://www.formula1.com/etc/designs/fom-website/fonts/F1Wide/Formula1-Wide.ttf

https://www.formula1.com/etc/designs/fom-website/fonts/F1Black/Formula1-Black.ttf