-
Notifications
You must be signed in to change notification settings - Fork 10
/
demonotebook.Rmd
47 lines (39 loc) · 1017 Bytes
/
demonotebook.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
---
title: "Analysis of gapminder data"
author: "David Mawdsley"
output:
word_document: default
pdf_document: default
html_notebook: default
---
In this notebook we will explore the gapminder data.
First we'll read in the data:
```{r}
library(readr)
library(ggplot2)
library(dplyr)
setwd("_episodes_rmd/")
gapminder <- read_csv("./data/gapminder-FiveYearData.csv",
col_types = cols(
country = col_character(),
year = col_integer(),
pop = col_double(),
continent = col_character(),
lifeExp = col_double(),
gdpPercap = col_double()
)
)
```
Let's investigate how life expectancy varies per continent:
```{r}
gapminder %>%
filter(year == 1997) %>%
group_by(continent, year) %>%
summarise(medianLifeExp=median(lifeExp))
```
And let's plot a graph:
```{r}
gapminder %>% filter(continent %in% c("Europe", "Americas")) %>%
ggplot(aes(x=year, y=gdpPercap, colour=country)) +
geom_line() + facet_wrap( ~ continent) + guides(colour="none")
```