-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld-data-bank.R
63 lines (42 loc) · 1.41 KB
/
world-data-bank.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
library("tidyverse")
library("readxl")
world_data <-
read_xlsx("data-raw/Data_Extract_From_World_Development_Indicators.xlsx",
"Data")
colnames(world_data) <- tolower(make.names(colnames(world_data)))
world_data <- world_data %>%
filter(!is.na(series.name))
world_data <- world_data %>%
select(-country.code,-series.code) %>%
gather(year, databank.value, -country.name,
-series.name) %>%
arrange(country.name, year)
world_data %>%
mutate(year = str_extract(year, "[0-9]+"),
year = as.integer(year),
databank.value = as.numeric(databank.value)) %>%
select(year, databank.value, everything()) %>%
write_csv("data-raw/tidied-databank-data.csv")
tidied_world_data <- read_csv("data-raw/tidied-databank-data.csv")
tidied_world_data %>%
filter(country.name == "Canada") %>%
ggplot(aes(x = year,
y = databank.value,
color = series.name)) +
geom_line() +
theme(legend.position = "bottom")
gg_my_plot <- tidied_world_data %>%
filter(series.name == "Pump price for diesel fuel (US$ per liter)") %>%
group_by(country.name) %>%
summarise(mean.value = mean(databank.value,
na.rm = TRUE)) %>%
ggplot(aes(x = country.name,
y = mean.value)) +
geom_col() +
coord_flip()
ggsave("my-beautiful-plot.png",
plot = gg_my_plot,
width = 10,
units = "in",
dpi = 300)
gg_my_plot