-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdp-life-expectancy.Rmd
56 lines (45 loc) · 1.45 KB
/
gdp-life-expectancy.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: "GDP and life expectancy"
output:
html_document:
fig_height: 3
fig_width: 6
---
```{r setup, echo=FALSE}
# hide code and messages from output
# set echo = TRUE to show code in output
# set message = TRUE to show messages in output
knitr::opts_chunk$set(echo = FALSE, message = FALSE)
```
```{r load-packages}
library(ggplot2)
library(dplyr)
```
```{r load-dataset}
gapminder <- read.csv("data/gapminder.csv")
```
The Gapminder dataset contains life expectancy and GDP per capita information for countries between for the following years: `r unique(gapminder$year)`.
```{r set-year}
# change here for analysis for another year
# make sure to choose a year for which there is data available
analysis_year <- 2007
```
In this report we analyze the relationship between GDP and life expectancy in `r analysis_year` overall and by year.
```{r filter-for-year}
gap_subset <- gapminder %>%
filter(year == analysis_year)
```
The figure below shows the relationship between these variables in all countries that we have data for in `r analysis_year`.
```{r overall}
ggplot(data = gap_subset, aes(x = gdpPercap, y = lifeExp)) +
geom_point() +
xlab("GDP per capita") +
ylab("Life expectancy")
```
It might also be of interest to visualize this relationship conditional on continent.
```{r by-continent}
ggplot(data = gap_subset, aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point() +
xlab("GDP per capita") +
ylab("Life expectancy")
```