-
Notifications
You must be signed in to change notification settings - Fork 0
/
head-to-head.Rmd
58 lines (50 loc) · 1.32 KB
/
head-to-head.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
title: "Formular 1 2021 Season - Head to Head comparisons"
output: html_notebook
---
```{r}
library(rvest)
library(xml2)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(hrbrthemes)
source("../R/colors.R")
```
```{r}
URL <- "https://www.formula1.com/en/results.html/2021/drivers.html"
page = read_html(URL)
raw_standings = page %>%
html_node(".resultsarchive-table") %>%
html_table() %>%
select(-c(1, 7))
raw_standings
```
```{r}
head_to_head = raw_standings %>%
group_by(Car) %>%
summarise(First=max(PTS), Second=min(PTS))
head_to_head$Car <- factor(head_to_head$Car, levels = head_to_head$Car[order(head_to_head$First)])
head_to_head
```
```{r}
ggplot(head_to_head) +
geom_segment(aes(x=Car, xend=Car, y=First, yend=Second, color=Car)) +
geom_point(aes(x=Car, y=First, size=First, color=Car)) +
geom_point(aes(x=Car, y=Second, size=Second, color=Car)) +
scale_color_manual(values=scuderia_colors()) +
coord_flip()+
theme_ft_rc(grid = "X") +
theme(
legend.position = "none"
) +
ggtitle("Formula 1 2021", "Head to Head Drivers Comparison") +
labs(
title = "Formula 1 2021 Season",
subtitle = "Head to Head Drivers Comparison",
caption = "Source: https://www.formula1.com/en/results.html/2021/drivers.html",
) +
xlab("") +
ylab("Points")
ggsave('../sample_chart.png', dpi = 600)
```