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.4.3 (2017-11-30)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Chinese (Traditional)_Taiwan.950
## [2] LC_CTYPE=Chinese (Traditional)_Taiwan.950
## [3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
## [4] LC_NUMERIC=C
## [5] LC_TIME=Chinese (Traditional)_Taiwan.950
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.20 mosaic_1.1.1 Matrix_1.2-12 mosaicData_0.16.0
## [5] ggformula_0.6.2 ggplot2_2.2.1 lattice_0.20-35 dplyr_0.7.4
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.15 highr_0.6 pillar_1.2.1 compiler_3.4.3
## [5] plyr_1.8.4 bindr_0.1 tools_3.4.3 digest_0.6.15
## [9] nlme_3.1-131 evaluate_0.10.1 tibble_1.4.2 gtable_0.2.0
## [13] pkgconfig_2.0.1 rlang_0.2.0 psych_1.7.8 parallel_3.4.3
## [17] yaml_2.1.17 ggdendro_0.1-20 bindrcpp_0.2 gridExtra_2.3
## [21] stringr_1.3.0 rprojroot_1.3-2 grid_3.4.3 mosaicCore_0.4.2
## [25] glue_1.2.0 R6_2.2.2 foreign_0.8-69 rmarkdown_1.9
## [29] reshape2_1.4.3 tidyr_0.8.0 purrr_0.2.4 magrittr_1.5
## [33] backports_1.1.2 scales_0.5.0 htmltools_0.3.6 MASS_7.3-47
## [37] splines_3.4.3 mnormt_1.5-5 assertthat_0.2.0 colorspace_1.3-2
## [41] labeling_0.3 stringi_1.1.6 lazyeval_0.2.1 munsell_0.4.3
## [45] broom_0.4.3