-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-gapminder.R
55 lines (40 loc) · 1.6 KB
/
01-gapminder.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
# load required packages
library(tibble)
library(ggplot2)
library(gapminder)
# view header of the dataset
gapminder
# view help file for the dataset
?gapminder
# generate a histogram of life expectancy
ggplot(data = ________, mapping = aes(x = ________)) +
geom________()
# generate separate histograms of life expectancy for each continent
# Hint: think about how to split your plots to show different subsets of data
ggplot(data = ________, mapping = aes(x = ________)) +
geom________() +
________(facets = vars(________))
# compare the distribution of life expectancy, by continent by generating a boxplot
ggplot(data = ________, mapping = aes(x = ________, y = ________)) +
geom________()
## redraw the plot, but this time use a violin plot
ggplot(data = ________, mapping = aes(x = ________, y = ________)) +
geom________()
# generate a scatterplot of the relationship between per capita GDP and life expectancy
ggplot(data = ________, mapping = aes(x = ________, y = ________)) +
geom________()
## add a smoothing line to the scatterplot
ggplot(data = ________, mapping = aes(x = ________, y = ________)) +
geom________() +
geom________()
## use color to identify whether this relationship differs by continent
ggplot(data = ________,
mapping = aes(x = ________, y = ________, color = ________)) +
geom________() +
geom________()
## bonus: identify the outlying countries on the right-side of the graph
## by labeling each observation with the country name
ggplot(data = ________,
mapping = aes(x = ________, y = ________, label = ________)) +
geom________() +
geom________()