Homework 2

Question 1

아래와 같이 자료을 불러들이자.

rm(list = ls())
library(gapminder)
library(tidyverse)
## -- Attaching packages ----------------------------------------------------------------------- tidyverse 1.2.1 --
## √ ggplot2 3.0.0     √ purrr   0.3.2
## √ tibble  2.1.1     √ dplyr   0.8.3
## √ tidyr   1.0.0     √ stringr 1.4.0
## √ readr   1.3.1     √ forcats 0.4.0
## -- Conflicts -------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
data("gapminder")

다음과 같이 요약통계량을 작성하자.

gapminder %>% 
  filter(year >= 1982) %>% 
  group_by(continent) %>% 
  summarise(n    = n(),
            mean = mean(gdpPercap),
            sd   = sd(gdpPercap))
## # A tibble: 5 x 4
##   continent     n   mean     sd
##   <fct>     <int>  <dbl>  <dbl>
## 1 Africa      312  2519.  2988.
## 2 Americas    150  8754.  7708.
## 3 Asia        198  9361. 10679.
## 4 Europe      180 19289.  9946.
## 5 Oceania      12 23445.  5154.

Question 2

대륙별 1인당 GDP 의 시간당 추세는 아래와 같이 구할 수 있다.

library(ggplot2)

gapminder %>% 
  filter(year >= 1982) %>% 
  group_by(continent, year) %>% 
  summarise(mean = mean(gdpPercap)) %>% 
  ggplot(mapping = aes(x = year, y = mean, color = continent)) +
  geom_point(aes(shape = continent)) +
  geom_line() +
  scale_color_brewer(palette = "Set1")