-
Notifications
You must be signed in to change notification settings - Fork 24
/
dplyr.R
64 lines (49 loc) · 1.59 KB
/
dplyr.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
60
61
62
63
64
library("tidyverse")
gapminder <- gapminder::gapminder
gapminder
gapminder %>% select(-gdpPercap)
year_country_gdp <- gapminder %>%
select(year, country, gdpPercap)
gapminder %>%
filter(year == 2002) %>%
ggplot(mapping = aes(x = continent, y = pop)) +
geom_boxplot()
gapminder %>%
filter(continent == "Europe") %>%
select(year, country, gdpPercap)
gapminder %>%
filter(country == "Norway") %>%
select(gdpPercap, lifeExp, year)
gapminder %>%
group_by(continent) %>%
summarize(mean_gdpPercap = mean(gdpPercap))
gapminder %>%
filter(continent == "Asia") %>%
group_by(country) %>%
summarize(mean_lifeExp = mean(lifeExp)) %>%
filter(mean_lifeExp == min(mean_lifeExp) |
mean_lifeExp == max(mean_lifeExp))
gapminder %>%
group_by(continent, year) %>%
summarize(mean_gdpPercap = mean(gdpPercap),
sd_gdpPercap = sd(gdpPercap),
mean_pop = mean(pop),
sd_pop = sd(pop))
gapminder %>%
mutate(gdp_billion = gdpPercap * pop / 10^9)
gapminder %>%
mutate(gdp_billion = gdpPercap * pop / 10^9) %>%
filter(year == 1987) %>%
group_by(continent) %>%
summarize(mean_lifeExp = mean(lifeExp),
mean_gdp_billion = mean(gdp_billion))
gapminder_country_summary <- gapminder %>%
group_by(country) %>%
summarize(mean_lifeExp = mean(lifeExp))
gapminder_country_summary
map_data("world") %>%
rename(country = region) %>%
left_join(gapminder_country_summary, by = "country") %>%
ggplot() +
geom_polygon(mapping = aes(x = long, y = lat, group = group,
fill = mean_lifeExp))