Chapter 4 2021.09.29. Quiz 4

library(gapminder)
library(tidyverse)
## -- Attaching packages ---------------------------- tidyverse 1.3.1 --
## √ tibble  3.1.4     √ dplyr   1.0.7
## √ tidyr   1.1.3     √ stringr 1.4.0
## √ readr   2.0.1     √ forcats 0.5.1
## √ purrr   0.3.4
## -- Conflicts ------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

4.1 Quiz 4-1

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

4.2 Quiz 4-2

gapminder %>%
  filter(year=="2007") %>%
  ggplot(mapping = aes(x = lifeExp, fill = continent)) +
  geom_histogram() +
  facet_grid(cols = vars(continent))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

4.3 Quiz 4-3

gapminder %>%
  filter(year=="2007") %>%
  ggplot(mapping = aes(y = lifeExp, fill = continent)) +
  geom_boxplot()

4.4 Quiz 4-4

ggplot(gapminder, aes(year, lifeExp, group = country, color = continent)) + geom_line()

4.5 Quiz 4-5

ggplot(gapminder, aes(year, lifeExp, group = country, color = continent)) + 
  geom_line() + 
  facet_grid(cols = vars(continent))

4.6 Quiz 4-6

library(corrplot)
## corrplot 0.90 loaded
data1 <- gapminder %>% filter(year=="2007")
data = data1[,4:6]
cor_matrix=cor(data)
corrplot.mixed(cor_matrix)

  • 교수님 방법
gapminder %>% 
  filter(year=="2007") %>%
  select(lifeExp, pop, gdpPercap) %>%
  cor() %>%
  corrplot.mixed()