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.3 (2020-02-29)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
##
## 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] ggplot2_3.3.0 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.5 dplyr_0.8.4
## [9] stringr_1.4.0 highr_0.8 tools_3.6.3 grid_3.6.3
## [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 digest_0.6.25 tibble_2.1.3
## [21] lifecycle_0.2.0 crayon_1.3.4 farver_2.0.3 purrr_0.3.3
## [25] glue_1.3.1 evaluate_0.14 rmarkdown_2.1 labeling_0.3
## [29] stringi_1.4.6 compiler_3.6.3 pillar_1.4.3 scales_1.1.0
## [33] pkgconfig_2.0.3