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.1 (2019-07-05)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Mojave 10.14.6
##
## 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.2.1 knitr_1.28
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.3 magrittr_1.5 tidyselect_1.0.0 munsell_0.5.0
## [5] colorspace_1.4-1 R6_2.4.1 rlang_0.4.4 dplyr_0.8.4
## [9] stringr_1.4.0 highr_0.8 tools_3.6.1 grid_3.6.1
## [13] gtable_0.3.0 xfun_0.12 withr_2.1.2 htmltools_0.4.0
## [17] assertthat_0.2.1 yaml_2.2.1 lazyeval_0.2.2 digest_0.6.25
## [21] tibble_2.1.3 lifecycle_0.1.0 crayon_1.3.4 farver_2.0.3
## [25] purrr_0.3.3 glue_1.3.1 evaluate_0.14 rmarkdown_2.1
## [29] labeling_0.3 stringi_1.4.6 compiler_3.6.1 pillar_1.4.3
## [33] scales_1.1.0 pkgconfig_2.0.3