#Import the dataset to the environment & load ggplot2
library(readr)
library(ggplot2)
pitstops <- read_csv("pitstops.csv")
## Parsed with column specification:
## cols(
##   Constructor = col_character(),
##   Time = col_double()
## )
head(pitstops)
## # A tibble: 6 x 2
##   Constructor  Time
##   <chr>       <dbl>
## 1 Mercedes     21.5
## 2 Mercedes     24.3
## 3 Mercedes     22.2
## 4 Mercedes     20.0
## 5 Mercedes     22.0
## 6 Mercedes     24.3
#Set Team Colors
teamColors <- c("#9B0000", "#DC0000", "#F0D787", "#FF8700", "#00D2BE", "#F596C8", "#1E41FF", "#FFF500", "#469BFF", "#FFFFFF")


ggplot(pitstops, aes(Constructor, Time, fill = factor(Constructor))) +
  #Box Plot
  geom_boxplot(color = "#4a4a68") +
  #Points
  geom_point(shape = 3, alpha = 0.5, color = "white") +
  #Set Y Axis Label, and remove X-Axis Label
  labs(title = expression(bold("Formula One")), subtitle = "2019 Pit Stop Times", y = "Time (Seconds)", x = "") +
  #Rotate x-axis text by 45 degrees
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  #Organize Constructors
  scale_x_discrete(limits=c("Haas", "Ferrari", "Renault", "Red Bull", "Williams", "McLaren", "Mercedes", "Toro Rosso", "Alfa Romeo", "Racing Point")) +
  #Adjust Y-Axis Marks Scale (Every 2 Seconds between 0 and 38)
  scale_y_continuous(breaks=seq(0,38,2)) +
  #Set Team Colors
  scale_fill_manual(values = teamColors) +
  #Remove the now redundant legend
  theme(legend.position = "none") +
  #Set Background and Text Colors
  theme(plot.background = element_rect(fill = "#15151d"),
        panel.background = element_rect(fill = "#15151d"),
        panel.grid.major = element_line(color = "#292933"),
        panel.grid.minor = element_line(color = "#292933"),
        plot.title = element_text(color = "white"),
        plot.subtitle = element_text(color = "white"),
        axis.text = element_text(color = "white"),
        axis.title.y = element_text(color = "white"))