Download and input the Gapminder data set.
dta <- read.csv("https://4va.github.io/biodatasci/data/gapminder.csv")
library(knitr)
kable(head(dta))
| country | continent | year | lifeExp | pop | gdpPercap |
|---|---|---|---|---|---|
| Afghanistan | Asia | 1952 | 28.801 | 8425333 | 779.4453 |
| Afghanistan | Asia | 1957 | 30.332 | 9240934 | 820.8530 |
| Afghanistan | Asia | 1962 | 31.997 | 10267083 | 853.1007 |
| Afghanistan | Asia | 1967 | 34.020 | 11537966 | 836.1971 |
| Afghanistan | Asia | 1972 | 36.088 | 13079460 | 739.9811 |
| Afghanistan | Asia | 1977 | 38.438 | 14880372 | 786.1134 |
The mean life expectancy is 59.4744394 years.
The years surveyed in this data include: 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007.
library(ggplot2)
ggplot(dta, aes(gdpPercap, lifeExp, color = continent)) +
geom_point() +
scale_x_log10() +
labs(x = "GDP", y = "Life Expectancy (years)") +
theme_bw()
Life Exp vs GDP
sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS 10.15
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
##
## locale:
## [1] zh_TW.UTF-8/zh_TW.UTF-8/zh_TW.UTF-8/C/zh_TW.UTF-8/zh_TW.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggplot2_3.3.0 knitr_1.22
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.1 magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0
## [5] colorspace_1.4-1 R6_2.4.0 rlang_0.4.5 stringr_1.4.0
## [9] highr_0.8 dplyr_0.8.1 tools_3.6.0 grid_3.6.0
## [13] gtable_0.3.0 xfun_0.7 withr_2.1.2 htmltools_0.3.6
## [17] assertthat_0.2.1 yaml_2.2.0 digest_0.6.18 tibble_2.1.1
## [21] crayon_1.3.4 purrr_0.3.2 glue_1.3.1 evaluate_0.13
## [25] rmarkdown_1.18 labeling_0.3 stringi_1.4.3 compiler_3.6.0
## [29] pillar_1.4.0 scales_1.0.0 pkgconfig_2.0.2