—
library(gapminder)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.4
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 1.0.0 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(corrplot)
## corrplot 0.90 loaded
gapminder
## # A tibble: 1,704 x 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
## 7 Afghanistan Asia 1982 39.9 12881816 978.
## 8 Afghanistan Asia 1987 40.8 13867957 852.
## 9 Afghanistan Asia 1992 41.7 16317921 649.
## 10 Afghanistan Asia 1997 41.8 22227415 635.
## # … with 1,694 more rows
#quiz 4-1.
gapminder %>%
filter(year=="2007") %>%
ggplot(aes(x=lifeExp, fill=continent))+geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#quiz 4-2.
gapminder %>%
filter(year=="2007") %>%
ggplot(aes(x=lifeExp, fill=continent))+geom_histogram()+facet_wrap(~continent)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#quiz 4-3.
gapminder %>%
filter(year=="2007") %>%
ggplot(aes(fill=continent))+geom_boxplot(aes(y=lifeExp))

#quiz 4-4.
gapminder %>%
ggplot(aes(x=year, y=lifeExp, group=country))+geom_line(aes(color=continent))

#quiz 4-5.
gapminder %>%
ggplot(aes(x=year, y=lifeExp, group=country))+geom_line(aes(color=continent))+facet_wrap(~continent)

#quiz 4-6.
gapminder %>%
filter(year=="2007") %>%
select(lifeExp, pop, gdpPercap) %>%
cor() %>%
corrplot.mixed()
