The interactive plot below is a scatterplot comparing starting grid position and final race position for all 10 F1 teams in the 2024 season. The dots are arranged by color, with a distinct color for each team. Plotly makes the graph interactive, as the user can hover their mouse over each dot to display driver name. The plot also allows for individual teams to be removed from the visualization for more clarity when looking at a certain team(s). One observation is the difference in data available for each team. Teams such as Williams has more points on the plot than most other teams due to mid-season driver swaps, which could provide better insight as to how the team is performing on an individual level throughout the season.
library(tidyverse)
library(plotly)
library(flexdashboard)
# Load data here
df <- read_csv("C:\\Users\\ual-laptop\\Downloads\\Formula1_2024season_raceResults.csv")
colnames(df)
## [1] "Track" "Position" "No" "Driver"
## [5] "Team" "Starting Grid" "Laps" "Time/Retired"
## [9] "Points" "Set Fastest Lap" "Fastest Lap Time"
Do the following:
geom_point()).names(df)[names(df) == "Starting Grid"] <- "Starting_Grid"
df$Position[is.na(df$Position)] <- 0
plot1 <- ggplot(data = df,
mapping = aes(x = Starting_Grid, y = Position,
color = Team, text = Driver)) +
geom_point () +
scale_x_log10(limits = c(min(df$Starting_Grid, na.rm = TRUE), max(df$Starting_Grid, na.rm = TRUE))) +
theme_minimal ()
interactive_plot <- ggplotly(plot1, tooltip = 'text')
interactive_plot
Make the plot interactive with ggplotly().
Make sure the hovering tooltip is more informative than the default.
Good luck and have fun!
Install the {flexdashboard} package and create a new R Markdown file in your project by going to File > New File… > R Markdown… > From Template > Flexdashboard.
Using the documentation for {flexdashboard} online, create a basic dashboard that shows a plot (static or interactive) in at least three chart areas. Play with the layout if you’re feeling brave.