library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.8
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 2.1.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(readxl)
library(naniar)
library(rmarkdown)
library(ggcorrplot)
library(countrycode)
dat <- read_excel('./BE_EM.xlsx') %>%
group_by(Code) %>%
distinct(Year, .keep_all = T) %>%
ungroup()
head(dat) %>%
paged_table()
Số liệu từ năm 2009 - 2020 (12 năm)
Mô tả các biến số có trong dataset được sử dụng để phân tích
read_excel('./BE_EM.xlsx', sheet = 2) %>%
paged_table()
dat %>%
gg_miss_var(show_pct = T)
## Warning: It is deprecated to specify `guide = FALSE` to remove a guide. Please
## use `guide = "none"` instead.
Đồ thị mô tả thứ hạng về số lượng missing value có trong các biến, như vậy có thể thấy biến TOE có nhiều missing nhất, kế tiếp là POE và DWF
tschart <- function(varlist) {
for (y in varlist) {
if (y == 'Year' | y == 'Code' | y == 'Country') {
next
} else {
print(
dat %>%
drop_na_(y) %>%
ggplot(aes_string(x = "Year", y = y)) +
geom_line(aes(col = Country)) +
geom_point(aes(col = Country)) +
theme_bw()
)
}
}
}
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
## Loading required package: sp
## rgeos version: 0.5-9, (SVN revision 684)
## GEOS runtime version: 3.9.1-CAPI-1.14.2
## Please note that rgeos will be retired by the end of 2023,
## plan transition to sf functions using GEOS at your earliest convenience.
## GEOS using OverlayNG
## Linking to sp version: 1.4-6
## Polygon checking: TRUE
world <- ne_countries(scale = "medium", returnclass = "sf")
Europe <- world[which(world$continent == "Europe"),]
dat2020 <- dat %>%
filter(Year == 2020)
europe_dat <- Europe %>%
left_join(dat2020, by = c("iso_a3" = "Code"))
europe_map <- function(y, title, fill_color) {
return(
europe_dat %>%
ggplot(aes_string(fill = y)) +
geom_sf() +
coord_sf(xlim = c(-25,50), ylim = c(35,70), expand = FALSE) +
theme_bw() +
ggtitle(title) +
scale_fill_gradientn(colours = c('gray', fill_color))
)
}
marine_minerals <- c(
'ECP',
'ENG',
'SPG',
'OGS',
'ES',
'SMQ'
)
tschart(varlist = marine_minerals)
Nhìn chung giai đoạn 2009 - 2020 việc khai thác ở đại dương có xu hướng giảm dần ở các nước biểu hiện thông qua biểu đồ biến động về 6 biến đại điện ở bên trên, nổi bật nhất là ENG (Khai thác khí tự nhiên)
europe_map('ECP', 'Khai thác dầu thô tại Châu Âu (năm 2020)', 'steelblue') +
annotate("text", x = -5, y = 59.5, label = "UNITED KINGDOM", size = 2.5)
Khai thác dầu thô năm 2020 cao nhất ở Anh (theo bộ số liệu)
europe_map('ENG', 'Khai thác khí tự nhiên tại Châu Âu (năm 2020)', 'red') +
annotate("text", x = 9.8, y = 45.2, label = "ITALY", size = 2.5)
Khai thác khí tự nhiên năm 2020 cao nhất ở Ý (theo bộ số liệu)
ocean_energy <- c(
'TOE',
'POE'
)
tschart(ocean_energy)
dat %>%
select(Country, Code, ocean_energy) %>%
drop_na() %>%
ggplot(aes(log(TOE), log(POE), col = Country)) +
geom_point() +
geom_smooth(method = 'lm', se = F, formula = y ~ x) +
theme_bw() +
ggtitle('Mối tương quan giữa POE và TOE') +
theme(
plot.title = element_text(face = "bold", hjust = 0.5)
)
## Note: Using an external vector in selections is ambiguous.
## ℹ Use `all_of(ocean_energy)` instead of `ocean_energy` to silence this message.
## ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
Xét mối liên hệ tương quan của 2 biến TOE (Truyền tải điện) và POE (Sản xuất điện) thấy được mối liên tương quan dương, thấy rằng khi mức truyền tải điện càng lớn thì mức độ sản xuất điện cũng nhiều ở các quốc gia
europe_map('TOE', 'Truyền tải điện tại Châu Âu (năm 2020)', 'yellow') +
annotate("text", x = 6, y = 54, label = "NETHERLANDS", size = 2.5)
Truyền tải điện năm 2020 cao nhất ở Hà Lan (Netherlands) (theo bộ số liệu)
europe_map('POE', 'Sản xuất điện tại Châu Âu (năm 2020)', 'yellow') +
annotate("text", x = 10.6, y = 52, label = "GERMANY", size = 2.4)
Sản xuất điện năm 2020 cao nhất ở Đức (Germany) (theo bộ số liệu)