getwd()
## [1] "C:/Users/kijun/Desktop"
library(dplyr)
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(gapminder)
y<-gapminder %>% group_by(year,continent) %>% summarise(c_cop=sum(pop))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
head(y,20)
## # A tibble: 20 × 3
## # Groups:   year [4]
##     year continent      c_cop
##    <int> <fct>          <dbl>
##  1  1952 Africa     237640501
##  2  1952 Americas   345152446
##  3  1952 Asia      1395357351
##  4  1952 Europe     418120846
##  5  1952 Oceania     10686006
##  6  1957 Africa     264837738
##  7  1957 Americas   386953916
##  8  1957 Asia      1562780599
##  9  1957 Europe     437890351
## 10  1957 Oceania     11941976
## 11  1962 Africa     296516865
## 12  1962 Americas   433270254
## 13  1962 Asia      1696357182
## 14  1962 Europe     460355155
## 15  1962 Oceania     13283518
## 16  1967 Africa     335289489
## 17  1967 Americas   480746623
## 18  1967 Asia      1905662900
## 19  1967 Europe     481178958
## 20  1967 Oceania     14600414
plot(log10(gapminder$gdpPercap),gapminder$lifeExp,col=gapminder$continent)
legend("bottomright",legend=levels((gapminder$continent)),
       pch=c(1:length(levels(gapminder$continent))),
       col=c(1:length(levels(y$continent))))
glimpse(gapminder)
## Rows: 1,704
## Columns: 6
## $ country   <fct> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, …
## $ year      <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, …
## $ lifeExp   <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.8…
## $ pop       <int> 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 12…
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134, …
library(ggplot2)

ggplot(gapminder,aes(x=gdpPercap,y=lifeExp,col=continent))+geom_point()+scale_x_log10()

ggplot(gapminder,aes(x=gdpPercap,y=lifeExp,col=continent))+geom_point(alpha=0.5)+scale_x_log10()

ggplot(gapminder,aes(x=gdpPercap,y=lifeExp,col=continent))+geom_point(alpha=0.5)+scale_x_log10()+facet_wrap(~year)

library(gapminder)
gapminder %>% filter(year==1952&continent=="Asia") %>% ggplot(aes(reorder(country,pop),pop))+geom_bar(stat="identity")+coord_flip()