Column

Births by ethnic group over time

Column

Deaths by ethnic group, age groups and year

Chart C

---
title: "ETHPOP"
author: "Nathan Green, Imperial College London"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(reshape2)
library(tibble)
library(plotly)
# library(ggthemes)
# library(gridExtra)
library(shiny)
library(knitr)

data_dir <- "C:/Users/ngreen1/Documents/R/cleanETHPOP/output_data"
```

```{r}
# readin population data
clean_births <- read.csv(paste0(data_dir, "/clean_births.csv"))
clean_deaths <- read.csv(paste0(data_dir, "/clean_deaths.csv"))
clean_inmigrants <- read.csv(paste0(data_dir, "/clean_inmigrants.csv"))
clean_outmigrants <- read.csv(paste0(data_dir, "/clean_outmigrants.csv"))
clean_pop <- read.csv(paste0(data_dir, "/clean_pop.csv"))
```

```{r}
# raw_data_dir <- "C:/Users/ngreen1/Documents/data"
# 
# # join ethnic group descriptions
# ethnic_grps <- read.csv(paste0(raw_data_dir, "/ETHPOP_ethnicgrps_Chapter18_PopulationProjections_Reese.csv"))
# 
# clean_births <- merge(clean_births, ethnic_grps,
#                       by.x = "ETH.group",
#                       by.y = "abbreviation")
# clean_deaths <- merge(clean_deaths, ethnic_grps,
#                       by.x = "ETH.group",
#                       by.y = "abbreviation")
```

Column {data-width=500}
-----------------------------------------------------------------------

### Births by ethnic group  over time

```{r}
# p <- 
#   clean_births %>% 
#   select(-X) %>% 
#   melt(id.vars = c("description", "year")) %>% 
#   as_tibble() %>% 
#   filter(variable == "tot_births") %>% 
#   mutate(description = as.factor(description),
#          value = as.numeric(value)) %>% 
#   ggplot(mapping = aes(x = year, y = value, col = description)) +
#   geom_line() + 
#   xlab("Year") + ylab("Population") +
#   theme_bw()  
# 
# ggplotly(p)
```

Column {data-width=500}
-----------------------------------------------------------------------

```{r}
# selectInput("year",
#             label = "Year: ",
#             choices = 2011:2060,
#             selected = 2011)
```


### Deaths by ethnic group, age groups and year

```{r}
# renderPlotly({
#   p <- 
#     clean_deaths %>% 
#     select(-X) %>% 
#     mutate(agegrp = factor(agegrp, levels = c("[0,5)",   "[5,10)",  "[10,15)", "[15,20)", "[20,25)", "[25,30)",
#                                               "[30,35)", "[35,40)", "[40,45)", "[45,50)", "[50,55)", "[55,60)",
#                                               "[60,65)", "[65,70)", "[70,75)", "[75,80)", "[80,85)", "[85,90)",
#                                               "[90,95)", "[95,100)", "[100,105)"))) %>% 
#     as_tibble() %>% 
#     filter(sex == "F",
#            year == 2011) %>% 
#            # year == as.numeric(input$year)) %>% 
#     mutate(description = as.factor(description),
#            deaths = as.numeric(deaths)) %>% 
#     ggplot(mapping = aes(x = agegrp, y = deaths, col = description, group = description)) +
#     geom_line() + 
#     geom_point() +
#     xlab("Age") + ylab("Population") +
#     theme_gdocs() + 
#     theme(axis.text = element_text(size = 7),
#           axis.text.x = element_text(angle = 60, hjust = 1))
#   
#   # ggplotly(p)
# })
```

### Chart C

```{r}

```