-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy path04-map2.R
More file actions
31 lines (23 loc) · 742 Bytes
/
04-map2.R
File metadata and controls
31 lines (23 loc) · 742 Bytes
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
library(repurrrsive)
gap_split_small <- gap_split[1:10]
countries <- names(gap_split_small)
# For each country create a ggplot of Life Expectancy through time
# with a title
# For one country
ggplot(gap_split_small[[1]], aes(year, lifeExp)) +
geom_line() +
labs(title = countries[[1]])
# For all countries
plots <- map2(gap_split_small, countries,
~ ggplot(.x, aes(year, lifeExp)) +
geom_line() +
labs(title = .y))
plots[[1]]
# Display all plots
walk(plots, print) # this might take awhile
# Save all plots
walk2(.x = plots, .y = countries,
~ ggsave(filename = paste0(.y, ".pdf"), plot = .x))
# Argh! I didn't want all those pictures in this directory,
# remove them all
file.remove(paste0(countries, ".pdf"))