---
title: "mapping coroner data"
author: "Jenna"
date: "June 16, 2020"
output: html_document
---

```{r setup, include=FALSE}
#knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE)

```

```{r}
library(ggmap)
library(tidyverse)
library(leaflet)
register_google(key = "AIzaSyCX4q1BY7uvj4Iy06mq0V2rIUvDGYQmCb4")
```

### Deaths by COVID-19, New Orleans
Label: race/ethnicity; place of death
```{r}
# covidDeathsRaw <- read_csv("FinalCoroner6.5.csv")
# 
# covidDeathsGC <- covidDeathsRaw %>%
#  mutate(fullAdd = paste(Address, Zip, sep = " ")) %>%
#   mutate_geocode(fullAdd)
# 
# save(covidDeathsGC, file = "covidDeathsGC.Rdata")

load("covidDeathsGC.Rdata")

covidDeaths <- covidDeathsGC %>%
  filter(!is.na(lat)) %>%
  mutate(ageGrp = NA,
         ageGrp = ifelse(Age < 50, "<50", ageGrp),
         ageGrp = ifelse(Age >= 50 & Age < 60, "50 - 60", ageGrp),
         ageGrp = ifelse(Age >= 60 & Age < 70, "60 - 70", ageGrp),
         ageGrp = ifelse(Age >= 70 & Age < 80, "70 - 80", ageGrp),
         ageGrp = ifelse(Age >= 80, "80+", ageGrp)) %>%
  mutate(group = NA, 
         group = ifelse(ageGrp =="<50", "red", group),
         group = ifelse(ageGrp =="50 - 60", "orange", group),
         group = ifelse(ageGrp =="60 - 70", "yellow", group),
         group = ifelse(ageGrp =="70 - 80", "green", group),
         group = ifelse(ageGrp =="80+","blue",group),
         
         groupNH = ifelse(NursingHome == "Yes", "blue", "orange"),
         
         # group = ifelse(`Location of death`== "Hospital", "blue", group),
         # group = ifelse(`Location of death`== "Decedent Resident", "green", group),
         # group = ifelse(`Location of death` == "Nursing Home", "yellow", group),
         label = paste(Race, `Location.of.death`, sep = " "))  %>%
  filter(!is.na(group))
  
roleIcons <- iconList(blue = makeIcon("icons/blue.png", iconWidth = 24, iconHeight =32),
  green = makeIcon("icons/green.png", iconWidth = 24, iconHeight =32),
  red = makeIcon("icons/red.png", iconWidth = 24, iconHeight =32),
  orange = makeIcon("icons/orange.png", iconWidth = 24, iconHeight =32),
  yellow = makeIcon("icons/yellow.png", iconWidth = 24, iconHeight =32))

cdMap <- leaflet(data = covidDeaths) %>% 
  setView(lng = -90, lat =30, zoom = 12) %>% 
  addProviderTiles(providers$Stamen.TonerLite) %>%
  addMarkers(~lon, ~lat, popup = "Sex", label = ~label) #

cdMap
```

```{r}


cdMap <- leaflet(data = covidDeaths) %>% 
  setView(lng = -90, lat =30, zoom = 12) %>% 
  addProviderTiles(providers$Stamen.TonerLite) %>%
  addMarkers(~lon, ~lat, popup = "Sex", label = ~label, icon = ~roleIcons[groupNH]) #

cdMap
```


### Deaths by COVID-19
#### Color-coded by age of death
<50, red    
50 - 60, orange    
60 - 70, yellow    
70 - 80, green    
80+, blue    
```{r}
cdMapAge <- leaflet(data = covidDeaths) %>% 
  setView(lng = -90, lat =30, zoom = 12) %>% 
  addProviderTiles(providers$Stamen.TonerLite) %>%
  addMarkers(~lon, ~lat, popup = "Sex", label = ~label, icon = ~roleIcons[group]) #

cdMapAge
```