library(gapminder)
## Warning: package 'gapminder' was built under R version 4.3.2
library(tidyverse)
## Warning: package 'dplyr' was built under R version 4.3.2
## Warning: package 'stringr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ 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
library(ggridges)
library(ggforce)
## Warning: package 'ggforce' was built under R version 4.3.2
# install.packages("colorspace", repos = "http://R-Forge.R-project.org")
library(colorspace)
# remotes::install_github("clauswilke/colorblindr")
library(colorblindr)
# devtools::install_github("clauswilke/dviz.supp", force = TRUE)
library(owidR)
## Warning: package 'owidR' was built under R version 4.3.2
a <- owid_search("GDP")
a1 <- owid(chart_id = "total-gdp-vs-gdp-per-capita-maddison")
a2 <- a1[a1$year == 2018, c(1,4,5)]
GDPVN <- 661488400000
GDPPer <-6814.142
a2$GDP1 <- round(a2$GDP/GDPVN, digits = 2)
a2$GDP1per <- round(a2$`GDP per capita`/GDPPer, digits = 2)
a3 <- a2[-c(46,47,87,103,146,172,173,174),]
a3$entity <- reorder(a3$entity, a3$GDP1per, decreasing = FALSE)
a4 <- dplyr::arrange(a3, a3$entity)
a5<- a4[c(58,53,39,52,121,63,81,103),]
library(ggplot2)
ggplot(a5, aes(x = reorder(entity, GDP1per), y = GDP1per, fill = ifelse(GDP1per > 1, "red", "blue"))) +
geom_col() +
scale_y_log10(breaks = c(1/16, 1/8, 1/4, 1/2, 1, 2, 4, 8, 16, 32, 64),
labels = c("1/16", "1/8", "1/4", "1/2", "1", "2", "4", "8", "16", "32", "64"),
name = "GDP relative to Viet Nam",
limits = c(.055, 70),
expand = c(0, 0)) +
scale_x_discrete(name = NULL) +
scale_fill_discrete(name = "Mức độ") +
coord_flip() +
theme_classic() +
theme(axis.line = element_blank(),
axis.ticks.length = grid::unit(0, "pt"),
axis.ticks.y = element_blank(),
plot.margin = margin(12, 6, 3, 1.5))+
theme(axis.text.x = element_text(face = "bold",
size = 10))+
theme(axis.text.y = element_text(face = "bold",
size = 10),
legend.position = c(0.7,0.5))+
geom_hline(yintercept = 1)+
labs(title = "So sánh GDP các nước Đông Nam Á với Việt Nam", caption = "Nguồn: Dinh Le")+
theme(plot.title = element_text(lineheight = 0.8,
face ="bold",
hjust = 0.5),
plot.caption = element_text(lineheight = 0.5,
face ="bold",
hjust = 1))+
theme(panel.background = element_rect(fill = "white"), panel.border = element_rect(colour = "darkgreen", fill = NA, linewidth = 0.75))
