Ở nhiệm vụ này chúng ta sẽ tự tìm 1 dataset và vẽ 20 đồ thị để mô tả và phân tích cho dữ liệu được chứa trong dataset này.
Ở đây, ta sẽ phân tích dataset CR7, đây là 1 dataset bao gồm thông số những bàn thắng của Cristiano Ronaldo trong sự nghiệp của anh ấy tính tới mùa giải 22/23
Trước tiên, ta gán dataset vào trong Rstudio
## Warning: package 'csv' was built under R version 4.3.3
Sau đó sử dụng lệnh str để xem được các thông số của bộ dữ liệu
## 'data.frame': 710 obs. of 13 variables:
## $ Season : chr "02/03" "02/03" "02/03" "02/03" ...
## $ Competition : chr "Liga Portugal" "Liga Portugal" "Liga Portugal" "Taca de Portugal Placard" ...
## $ Matchday : chr "6" "6" "8" "Fourth Round" ...
## $ Date : chr "10-07-02" "10-07-02" "10/26/02" "11/24/02" ...
## $ Venue : chr "H" "H" "A" "H" ...
## $ Club : chr "Sporting CP" "Sporting CP" "Sporting CP" "Sporting CP" ...
## $ Opponent : chr "Moreirense FC" "Moreirense FC" "Boavista FC" "CD Estarreja" ...
## $ Result : chr "3:00" "3:00" "1:02" "4:01" ...
## $ Playing_Position: chr "LW" "LW" "" "" ...
## $ Minute : chr "34" "90+5" "88" "67" ...
## $ At_score : chr "2:00" "3:00" "1:02" "3:00" ...
## $ Type : chr "Solo run" "Header" "Right-footed shot" "Left-footed shot" ...
## $ Goal_assist : chr "" "Rui Jorge" "Carlos Martins" "Cesar Prates" ...Ở đây, một số thông tin cơ bản ta có thể thấy đó là bộ dữ liệu này có 710 quan sát và 13 cột. Trong đó bao gồm
-Season: Mùa giải
-Competition: Giải đấu
-Matchday: Vòng đấu
-Date: Ngày duễn ra
-Venue: Sân nhà hay khách
-Club: CLB
-Opponent: Đối thủ
-Result: Kết quả
-Playing_Position: Vị trí thi đấu
-Minute: Phút ghi bàn
-At_score: Tỉ số
-Type: Cách ghi bàn
-Goal_assist: Người kiến tạo
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
Long %>% group_by(Club) %>% summarise(n = n()) %>%
ggplot(aes(Club,n)) +
geom_col(fill='orange') +
geom_text(aes(label = n),vjust = 2, color = 'black') +
labs(x = 'Loại', y = 'CLB')
### Biểu đồ 2 : bàn thắng mà CR7 đã ghi bàn theo từng vị trí
Long %>% group_by(Playing_Position) %>% summarise(n = n()) %>%
ggplot(aes(Playing_Position,n)) +
geom_col(fill='orange') +
geom_text(aes(label = n),vjust = 2, color = 'black') +
labs(x = 'Loại', y = 'CLB')Long %>% group_by(Type) %>% summarise(n = n()) %>%
ggplot(aes(Type,n)) +
geom_col(fill='orange') +
geom_text(aes(label = n),vjust = 2, color = 'black') +
labs(x = 'Loại', y = 'CLB')## Warning: Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning: Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
Laliga chính là giải đấu CR7 ghi nhiều nhất với ngay sau đó là UCL
## Warning: Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
Long %>% group_by(Type) %>% summarise(n = n()) %>%
ggplot(aes(x = '', y = n,fill = Type)) +
geom_col() +
geom_text(aes(label = n),position = position_stack(vjust = 2))Long %>% group_by(Competition) %>% summarise(n = n()) %>%
ggplot(aes(x = '', y = n,fill = Competition)) +
geom_col() +
coord_polar('y')## Warning: Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning: Groups with fewer than two data points have been dropped.
## Groups with fewer than two data points have been dropped.
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
Long %>% group_by(Club) %>% summarise(n = n()) %>%
ggplot(aes(x = '', y = n,fill = Club)) +
geom_col(Club = 'black') +
coord_polar('y') +
geom_text(aes(x = 1.3, label = n),position = position_stack(vjust = .5)) +
theme_void()## Warning in geom_col(Club = "black"): Ignoring unknown parameters: `Club`
Long %>% group_by(Competition) %>% summarise(n = n()) %>%
ggplot(aes(Competition,n)) +
geom_col(fill='orange') +
geom_text(aes(label = n),vjust = 0, color = 'black') +
labs(x = 'Giải đấu', y = 'số lượng')
CR7 đã ghi bàn tất cả 17 giải đấu trải dài từ Copa del Ray cho đến Saudi
proleague
Một số giải đấu nổi bật: Laliga: 311 bàn Copa del Ray: 22 bàn Premier League: 103 bàn Seria A: 81 bàn UCL: 140 bàn
Long %>% group_by(Playing_Position) %>% summarise(n = n()) %>%
ggplot(aes(Playing_Position,n)) +
geom_col(fill='orange') +
geom_text(aes(label = n),vjust = 0, color = 'black') +
labs(x = 'Vị trí', y = 'Số lượng')
Ta có : CF: 212 LW: 361 RW: 79 Còn lại 58 bàn bộ dữ liệu không cho ta
biết CR7 ghi bàn ở vị trí nào
Long %>% group_by(Club,Venue) %>% summarise(n=n()) %>%
ggplot(aes(x = Club,y = n)) +
geom_col(position = 'dodge') +
facet_wrap(~Venue) +
geom_text(aes(label = n),vjust = 0, color = 'black') +
labs(x = 'Loại', y = 'Số lượng')## `summarise()` has grouped output by 'Club'. You can override using the
## `.groups` argument.
Nhìn vào bảng, ta có thể thấy rằng khi được đá ở sân nhà (H) hiệu suất
ghi bàn của CR7 có phần nhỉnh hơn khi phải đá ở sân khách (A)
Long %>% group_by(Playing_Position,Type) %>% summarise(n=n()) %>%
ggplot(aes(x = Playing_Position,y = n)) +
geom_col(position = 'dodge') +
facet_wrap(~Type) +
geom_text(aes(label = n),vjust = 0, color = 'black') +
labs(x = 'Loại', y = 'Số lượng')## `summarise()` has grouped output by 'Playing_Position'. You can override using
## the `.groups` argument.
Nhìn vào các bảng số liệu, dễ dàng nhận ra rằng CR7 ghi bàn nhiều nhất
khi được đá ở vị trị cánh trái trên hàng tấn công(LW) và cách thức mà
CR7 dùng để ghi bàn nhiều nhất là sử dụng chân phải
Long %>% group_by(Club,Playing_Position) %>% summarise(n=n()) %>%
ggplot(aes(x = Playing_Position,y = n)) +
geom_col(position = 'dodge') +
facet_wrap(~Club) +
geom_text(aes(label = n),vjust = 0, color = 'black') +
labs(x = 'Loại', y = 'Số lượng')## `summarise()` has grouped output by 'Club'. You can override using the
## `.groups` argument.
Ta thấy ở real madrid, cr7 đá ở LW là chủ yếu tuy nhiêu CF lại là vị trí
mà CR7 thi đấu nhiều hơn sau khi anh rời real
## `summarise()` has grouped output by 'Club'. You can override using the
## `.groups` argument.
Long %>% ggplot(aes(x = Club, y = n)) +
geom_col(data = Long %>% filter(Playing_Position == 'RW'), fill = 'red') +
geom_col(data = Long %>% filter(Playing_Position == 'LW'), fill = 'blue')
Từ bảng ta có thể thấy Cr7 chỉ chủ yếu thi đấu LW và chỉ thay đổi đá RW
khi thi đấu ở MU