-
Notifications
You must be signed in to change notification settings - Fork 10
/
RNotebookExample.Rmd
62 lines (46 loc) · 2.45 KB
/
RNotebookExample.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
61
62
---
title: "RNotebookExample"
author: "Alexia Cardona"
date: "18/02/2020"
---
This report contains the analysis of the `gapminder` dataset and contains the results of the top Countries with the largest life expectancy in Europe. The analysis is based on data from 2007. The report also analyzes how life expectancy changed over the years in Europe.
This report was generated using R and the code to extract the European 2007 data is as follows:
```{r intro-chunk, message=FALSE}
#load tidyverse library
library(tidyverse) # used for data manipulation
library(rmarkdown) # used for paged_table function
library(kableExtra) # used for table
#read file into R
pop_data <- read_csv("data/gapminder_data.csv")
#create a table with data from European countries in 2007 showing the countries with the largest life expectancy at the top
euro_data_tbl <- pop_data %>%
filter(continent == "Europe" & year == 2007) %>%
select(-continent, -year) %>%
arrange(desc(lifeExp)) %>%
rename(Country = country, "Population Size" = pop, "Life Expectancy" = lifeExp, "GDP" = gdpPercap)
```
The results in euro_data_tbl are displayed in the Table below:
```{r kable-chunk, echo=FALSE}
euro_data_tbl %>%
kable(caption="European countries ordered by greatest life expectancy from 2007 data") %>%
kable_styling(bootstrap_options = "striped", full_width = F) %>%
scroll_box(width = "100%", height = "200px")
```
A better way to display this table is with pagination as follows:
```{r paged-table-chunk, echo=FALSE}
paged_table(euro_data_tbl)
```
Next, the life expectancy in Europe is observed across different years. The aim of this is to check if there was a change in life expectancy over the years. The data used for the life expectancy over the years analysis is the gapminder data and the following data manipulation was performed:
```{r fig-data-chunk}
#keep on European data and change year to factor
euro_data_fig <- pop_data %>%
filter(continent == "Europe") %>%
mutate(year=as_factor(year))
```
The life expactancy over the years is plotted as following:
```{r fig-chunk, fig.cap="Life Expectancy in Europe over the years"}
euro_data_fig %>%
ggplot(mapping=aes(x=year, y=lifeExp)) +
geom_violin() +
stat_summary(fun.y = median, geom = "point")
```