-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hands-on.R
60 lines (44 loc) · 1.89 KB
/
Hands-on.R
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
59
# PACKAGES NEEDED ####
list.of.packages <- c('WDI', 'dplyr', 'ggplot2', 'ggthemes', 'knitr', 'kableExtra', 'rnaturalearth', 'tidyverse', 'ggrepel')
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
lapply(list.of.packages, library, character.only = T, quietly = T)
# SLIDE 2 ####
# Search for "GDP"
WDIsearch('GDP')
# Save results for "GDP"
GDP_search <- WDIsearch('GDP')
# SLIDE 3 ####
# indicator = NY.GDP.PCAP.KD / name = GDP per capita (constant 2010 US$)
indicator <- c("GDP per capita" = 'NY.GDP.PCAP.KD')
dat1 <- WDI(indicator, country=c('FR', 'BR'), end = 2019)
head(dat1)
# indicators = NY.GDP.PCAP.KD and NY.GDP.PCAP.KN / names = GDP per capita (constant 2010 US$) and GDP per capita (constant LCU)
indicators <- c("GDP per capita (US$)" = 'NY.GDP.PCAP.KD', "GDP per capita (LCU)" = "NY.GDP.PCAP.KN")
dat2 <- WDI(indicators, country=c('FR', 'BR'), end = 2019)
head(dat2)
# SLIDE 4 ####
# GDP per capita for France and Brazil
ggplot(dat1, aes(year, `GDP per capita`, color=country)) + geom_line() +
xlab('Year') + ylab('GDP per capita')
# SLIDE 5 ####
# GDP per capita (US$ and local currency unity) for France and Brazil
ggplot(dat2, aes(year, color=country)) +
geom_line(aes(year, `GDP per capita (US$)`)) +
geom_line(aes(year, `GDP per capita (LCU)`), linetype = "dashed") +
xlab('Year') + ylab('GDP per capita') +
labs(caption = "GDP per capita (US$), solid; GDP per capita (LCU), dashed") +
theme_economist() +
scale_colour_economist()
# SLIDE 6 ####
Data_info <- WDI_data
Data_series <- as.data.frame(Data_info$series) %>%
filter(indicator == "NY.GDP.PCAP.KD")
colnames(Data_series)
Data_series$description
# SLIDE 7 ####
Data_countries <- as.data.frame(Data_info$country)
Data_countries %>%
kable("html") %>%
kable_styling(font_size = 11) %>%
scroll_box(width = "100%", height = "60%")