-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
61 lines (51 loc) · 1.71 KB
/
index.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
57
58
59
60
---
title: "Gapminder Analysis"
author: "Joel Nitta"
date: "`r Sys.Date()`"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
tar_load(c(
gapminder,
life_exp_mods
))
```
## Data
The `gapminder` dataset includes `r gapminder$country %>% n_distinct()` countries with per capita GDP, population, and life expectancy data from `r gapminder$year %>% min()` to `r gapminder$year %>% max()`.
## Methods
We fit a linear model of life expectancy by year for each country.
## Results
Asian countries showed the biggest gains in life expectancy over time, with European countries the least.
African and American countries have a wide spread of values.
```{r plot-mod, echo = FALSE, include = TRUE, fig.cap= "Results of modeling life expectancy over time by country. Only significant models shown (*p* < 0.05)."}
# Tidy modeling output data
life_exp_mods_for_plot <-
life_exp_mods %>%
filter(term == "year_rel", p.value < 0.05) %>%
left_join(
unique(select(gapminder, country, continent)),
by = "country"
) %>%
mutate(country = fct_reorder(country, estimate))
# Plot the modeling results
ggplot(
life_exp_mods_for_plot,
aes(x = estimate, y = country, fill = continent)) +
geom_errorbarh(
aes(xmax = estimate + std.error, xmin = estimate - std.error),
color = "grey40") +
geom_col() +
scale_x_continuous(name = "Change in life expectancy per year") +
scale_fill_brewer(palette = "Set1", name = "Continent") +
theme_bw() +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank()
)
```