---
title: "R Notebook"
output:
  html_document:
    df_print: paged
---

# Exercises on scales and colours
Comment the code. Look at the source data on the web if you need. Say in your 
own words what the code is doing and why the author may want this. What can she
be going to investigate with these tables? There are some hint questions 
scattered around in the text, but try to tell as much as you can associate with the 
code. Feel free to guess. Set your programming intuition free! 


------EXERCISE 1 -----------

__What does the url address represent?__

```{r message=FALSE}
library(tidyverse)
library(gapminder)
geo <- read_csv("https://raw.githubusercontent.com/open-numbers/ddf--gapminder--fasttrack/master/ddf--entities--geo--country.csv")

```


```{r}
glimpse(geo)
```

_What happens next below?_

```{r}
geo <- geo %>% dplyr::select(country, income_groups, main_religion_2008,
                             name, world_6region)
glimpse(geo)
```

```{r message=FALSE}
marriage1 <- read_csv("https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/countries-etc-datapoints/ddf--datapoints--age_at_1st_marriage_women--by--geo--time.csv")
```

```{r}
glimpse(marriage1)
```

```{r message=FALSE}
mar1_geo <- dplyr::inner_join(marriage1, geo, by = c("geo" = "country"))  
glimpse(mar1_geo)  
```

```{r}
mar1_comparison_time <- mar1_geo %>% 
  dplyr::mutate(past_20_years = 
                  dplyr::if_else(condition = time > 2000, true = "past 20 years", false = "old times"))
```

```{r}
glimpse(mar1_comparison_time)
```

---STOP HERE-----END OF EXERCISE 1
__Feel free to look up unknown functions (you need not study them in depth now).__
__What is going on here?__

```{r}
allgap <- dplyr::right_join(x = gapminder::gapminder_unfiltered, y = mar1_comparison_time, by = c("country" = "name", "year" = "time" ))
glimpse(allgap)
```

__What is on this plot? What can the line represent?__


```{r}
allgap %>% ggplot() + 
  geom_point(mapping = aes(x = gdpPercap, y = age_at_1st_marriage_women, 
                           color = continent)) + 
  geom_smooth(mapping = aes(x = gdpPercap, y = age_at_1st_marriage_women), method = "lm")
```
__How about this plot? Does the question yield an interesting answer?__ 
```{r}
allgap %>% ggplot() + 
  geom_point(mapping = aes(x = pop, y = age_at_1st_marriage_women, 
                           color = continent)) + 
  scale_x_continuous(trans = "log10") + 
  geom_smooth(aes(x = pop, y = age_at_1st_marriage_women), method = "lm")
```

```{r}
allgap %>% ggplot() + 
  geom_point(mapping = aes(y = pop, x = age_at_1st_marriage_women, 
                           color = continent)) + 
  scale_y_continuous(trans = "log10") + 
  geom_smooth(aes(y = pop, x = age_at_1st_marriage_women), method = "lm")
```






















































