Health

Column 1

Diagonesed High Blood Pressure Patients Per 100 Residents

Diagonozed Diabetes Patients Per 100 Residents

Diagonozed COPD Patients Per 100 Residents

Diagonozed Asthma Patients Per 100 Residents

Mental Health Visits Per 100 Residents

Number of Healthcare Providers Per Neighbourhood

Column 2

Average Family Income In the Neighbourhood

Number of Visible Minority Residents Per Square Kilometer

Number of Senior Citizen Residents Per Square Kilometer

Tree Counts Each Neighbourhood

Tree Counts Each Neighbourhood

Average Family Income In the Neighbourhood

Education

Column 1

Learing Opportunity Index - Elementary Schools

Learing Opportunity Index - Secondary Schools

Column 2

Average Family Income In the Neighbourhood

Number of Visible Minority Residents per Square Kilometer

Safety

Column 1

Drug Arrests Per 1000 Residents

Sexual Assaults Per 1000 Residents

Vehicle Thefts Per 1000 Residents

Break & Enters Per 1000 Residents

Column 2

Number of Visible Minority Residents per Square Kilometer

Number of Visible Minority Residents per Square Kilometer

Number of Tree Counts Each Neighbourhood

Number of Visible Minority Residents per Square Kilometer

Know Your Neighbourhood

Mouse Over To Get Neighbourhood

---
title: "Facts on Toronto Neighbourhood"
author: "Muralidhar, M.A."
date: "January 30, 2019"
output: 
  flexdashboard::flex_dashboard:
    social: menu
    orientation: columns
    vertical_layout: scroll
    source_code: embed
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(grid)
library(rgdal)
library(tmap)
library(ggplot2)
library(dplyr)

# read in the shapefile
TorontoMap = readOGR(dsn = "data", layer = "NEIGHBORHOODS_WGS84")

# Retain map for leaflet legend
toronto_leaflet <- TorontoMap
# remove the column AREA_S_CD
toronto_leaflet@data$AREA_S_CD <- NULL

# load related data on health and wellbeing in the City
chronicDiseases <- read.csv("data/Toronto/ChronicDiseases.csv")
WellbeingToronto <- read.csv("data/wellbeing_toronto_2011.csv")
safety <- readRDS("safety.rds")
counties <- readRDS("counties.rds")
secondarySchoolcounties <- readRDS("secondarySchoolcounties.rds")

# AREA_S_CD represents the neighbourhood ID, 
# but this variable was read in as character string 
# because of the way it was coded in Excel.
# The variable was then converted to a FACTOR variable when imported in R.
class(TorontoMap$AREA_S_CD) # factor

TorontoMap$AREA_S_CD<-as.numeric(TorontoMap$AREA_S_CD) 
#perform the join
TorontoMap@data <- left_join(TorontoMap@data, chronicDiseases, by = c('AREA_S_CD' = 'Neighb_ID'))
TorontoMap@data <- left_join(TorontoMap@data, WellbeingToronto, by = c('AREA_S_CD' = 'Neighbourhood.Id'))

# use the tmap package to view some of the data we just joined
#qtm(TorontoMap, "PopPerSqKm") # plot the basic map
TorontoMap@data$SeniorsPerSqKm  <-  round(TorontoMap@data$Seniors.55.and.over / TorontoMap@data$Total.Area, 0) 
TorontoMap@data$VisbMinorityPerSqKm  <-  round(TorontoMap@data$Visible.Minority.Category / TorontoMap@data$Total.Area, 0) 
TorontoMap@data$NotVisbMinorityPerSqKm  <-  round(TorontoMap@data$Not.a.Visible.Minority / TorontoMap@data$Total.Area, 0) 


# load related data on health and wellbeing in the City
TorontoHealth <- read.csv("data/City_Tor_WB-Health_2011.csv")

library(sf)  
d <- st_read('data\\NEIGHBORHOODS_WGS84.shp',stringsAsFactors = F) 
d$centroid <- st_centroid(d$geometry) 
d$AREA_S_CD<-as.numeric(d$AREA_S_CD)

#perform the join
d <- left_join(d, TorontoHealth, by = c('AREA_S_CD' = 'NID'))
safety_sf <- left_join(d, safety, by = c('AREA_S_CD' = 'Neighbourhood Id'))
# get the street tree count for neighborhood
treeCount <- st_read('data\\GTATreeCount.shp',stringsAsFactors = F)

# get the fast food restaurant
fastFood <- st_read('data\\fastFoodCount.shp',stringsAsFactors = F)
```

# Health

## Column 1

### Diagonesed High Blood Pressure Patients Per 100 Residents

```{r echo = FALSE}
        tm_shape(TorontoMap) + tm_polygons("HighBloodPressure",style=c("kmeans"),
                                          palette="PuBu",
                                          stretch.palette = TRUE,
                                          title=c("High Blood Pressure Patients Per 100"),
                                          position = c("left","top")) +
  tm_credits("Source: http://ontariohealthprofiles.ca/ \n File: 3_ahd_db_ast_hbp_mhv_copd_neighb_2015_LHIN_8.xls \n Analysis:Murali", position=c("right", "bottom"))
```

### Diagonozed Diabetes Patients Per 100 Residents

```{r echo = FALSE}
tm_shape(TorontoMap) + tm_polygons(c("Diabetes"), 
                                          style=c("kmeans"),
                                          palette="PuBu",
                                          stretch.palette = TRUE,
                                          title=c("Diabetes Patients Per 100 ")) +
  tm_legend(position = c("right","bottom"))+
  tm_credits("Source: http://ontariohealthprofiles.ca/ \n File: 3_ahd_db_ast_hbp_mhv_copd_neighb_2015_LHIN_8.xls \n Analysis:Murali", position=c("right", "bottom"))
```

### Diagonozed COPD Patients Per 100 Residents

```{r echo = FALSE}
tm_shape(TorontoMap) + 
  tm_polygons(c("COPD"), 
              style=c("kmeans"),
              palette="PuBu",
              stretch.palette = TRUE,
              title=c("COPD Patients Per 100 ")) +
  tm_legend(position = c("right","bottom"))+
  tm_credits("Source: http://ontariohealthprofiles.ca/ \n File: 3_ahd_db_ast_hbp_mhv_copd_neighb_2015_LHIN_8.xls \n Analysis:Murali", position=c("right", "bottom"))
```

### Diagonozed Asthma Patients Per 100 Residents

```{r echo = FALSE}
tm_shape(TorontoMap) + 
   tm_polygons(c("Asthma"), 
               style=c("kmeans"),
               palette="PuBu",
               stretch.palette = TRUE,
               title=c("Asthma Patients Per 100 ")) +
   tm_legend(position = c("right","bottom"))+
   tm_credits("Source: http://ontariohealthprofiles.ca/ \n File: 3_ahd_db_ast_hbp_mhv_copd_neighb_2015_LHIN_8.xls \n Analysis:Murali", position=c("right", "bottom"))
``` 

### Mental Health Visits Per 100 Residents

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons( c("MentalHealthVisits"), 
              style=c("kmeans"),
              palette="PuBu",
              stretch.palette = TRUE,
              title=c("Mental Health Visits Per 100 ")) +
  tm_legend(position = c("right","bottom")) +
  tm_credits("Source: http://ontariohealthprofiles.ca/ \n File: 3_ahd_db_ast_hbp_mhv_copd_neighb_2015_LHIN_8.xls \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Healthcare Providers Per Neighbourhood

```{r echo = FALSE}
  tm_shape(d) + 
  tm_polygons(c("HealthProviders"), 
              style=c("kmeans"),
              palette="PuRd",
              stretch.palette = TRUE,
              title=c("Healthcare Providers Count")) +
  tm_legend(position = c("right","bottom"))+
  tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  City_Tor_WB-Health_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

## Column 2

### Average Family Income In the Neighbourhood

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons("Average.Family.Income",style=c("kmeans"),
                  palette="Greens",
                  stretch.palette = TRUE,
                  title=c("Average Family Income $")) +
   tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Visible Minority Residents Per Square Kilometer

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons(c("VisbMinorityPerSqKm"), 
              style=c("kmeans"),
              palette= "Purples",
              stretch.palette = TRUE,
              title=c("Visible Minorities Per Sq.Km.")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Senior Citizen Residents Per Square Kilometer

```{r echo = FALSE}
  tm_shape(TorontoMap) +
  tm_polygons(c("SeniorsPerSqKm"),
               style=c("kmeans"),
               palette="Purples",
               stretch.palette = TRUE,
               title=c("Seniors Per Sq.Km.")) +
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Tree Counts Each Neighbourhood

```{r echo = FALSE}
tm_shape(treeCount) +
          tm_polygons( c("NUMPOINTS"),
               style=c("kmeans"),
               palette="YlGn",
               stretch.palette = TRUE,
               title=c("Tree counts in Neighborhood ")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Tree Counts Each Neighbourhood

```{r echo = FALSE}
tm_shape(treeCount) +
          tm_polygons( c("NUMPOINTS"),
               style=c("kmeans"),
               palette="YlGn",
               stretch.palette = TRUE,
               title=c("Tree counts in Neighborhood ")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Average Family Income In the Neighbourhood

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons("Average.Family.Income",style=c("kmeans"),
                  palette="Greens",
                  stretch.palette = TRUE,
                  title=c("Average Family Income $")) +
   tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

# Education

## Column 1

### Learing Opportunity Index - Elementary Schools

```{r echo = FALSE}
   tm_shape(counties) + 
   tm_polygons(c("Score_2017"), 
               style=c("kmeans"),
               palette="YlOrRd",
               stretch.palette = TRUE,
               title=c("Learning Opportunities Index - 2017")) +
   
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.tdsb.on.ca \n LOI2017.pdf \n Analysis:Murali", position=c("right", "bottom"))
```

### Learing Opportunity Index - Secondary Schools

```{r echo = FALSE}
   tm_shape(secondarySchoolcounties) + 
   tm_polygons(c("Sc_2017"), 
               style=c("kmeans"),
               palette="YlOrRd",
               stretch.palette = TRUE,
               title=c("Learning Opportunities Index - 2017")) +
   
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.tdsb.on.ca \n LOI2017.pdf \n Analysis:Murali", position=c("right", "bottom"))
```

## Column 2

### Average Family Income In the Neighbourhood

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons("Average.Family.Income",style=c("kmeans"),
                  palette="Greens",
                  stretch.palette = TRUE,
                  title=c("Average Family Income $")) +
   tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Visible Minority Residents per Square Kilometer

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons(c("VisbMinorityPerSqKm"), 
              style=c("kmeans"),
              palette="Purples",
              stretch.palette = TRUE,
              title=c("Visible Minorities Per Sq.Km.")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

# Safety

## Column 1

### Drug Arrests Per 1000 Residents

```{r echo = FALSE}
   tm_shape(safety_sf) + 
   tm_polygons(c("Drug Arrests"), 
               style=c("kmeans"),
               palette="YlOrRd",
               stretch.palette = TRUE,
               title=c("Drug Arrests Per 1000")) +
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  WB-Safety.xlsx \n Analysis:Murali", position=c("right", "bottom"))
```

### Sexual Assaults Per 1000 Residents

```{r echo = FALSE}
   tm_shape(safety_sf) + 
   tm_polygons(c("Sexual Assaults"), 
               style=c("kmeans"),
               palette="YlOrRd",
               stretch.palette = TRUE,
               title=c("Sexual Assaults Per 1000")) +
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  WB-Safety.xlsx \n Analysis:Murali", position=c("right", "bottom"))
```

### Vehicle Thefts Per 1000 Residents

```{r echo = FALSE}
tm_shape(safety_sf) + 
   tm_polygons(c("Vehicle Thefts"), 
               style=c("kmeans"),
               palette="YlOrRd",
               stretch.palette = TRUE,
               title=c("Vehicle Thefts Per 1000")) +
   
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  WB-Safety.xlsx \n Analysis:Murali", position=c("right", "bottom"))
```

### Break & Enters Per 1000 Residents

```{r echo = FALSE}
   tm_shape(safety_sf) + 
   tm_polygons(c("Break & Enters"), 
               style=c("kmeans"),
               palette="YlOrRd",
               stretch.palette = TRUE,
               title=c("Break & Enters Per 1000")) +
   
   tm_legend(position = c("right","bottom")) +
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  WB-Safety.xlsx \n Analysis:Murali", position=c("right", "bottom"))
```

## Column 2

### Number of Visible Minority Residents per Square Kilometer

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons(c("VisbMinorityPerSqKm"), 
              style=c("kmeans"),
              palette="YlOrBr",
              stretch.palette = TRUE,
              title=c("Visible Minorities Per Sq.Km.")) +
  tm_legend(position = c("right","bottom"))+
  tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Visible Minority Residents per Square Kilometer

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons(c("VisbMinorityPerSqKm"), 
              style=c("kmeans"),
              palette="YlOrBr",
              stretch.palette = TRUE,
              title=c("Visible Minorities Per Sq.Km.")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Tree Counts Each Neighbourhood

```{r echo = FALSE}
tm_shape(treeCount) +
          tm_polygons( c("NUMPOINTS"),
               style=c("kmeans"),
               palette="YlGn",
               stretch.palette = TRUE,
               title=c("Tree counts in Neighborhood ")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

### Number of Visible Minority Residents per Square Kilometer

```{r echo = FALSE}
  tm_shape(TorontoMap) + 
  tm_polygons(c("VisbMinorityPerSqKm"), 
              style=c("kmeans"),
              palette="YlOrBr",
              stretch.palette = TRUE,
              title=c("Visible Minorities Per Sq.Km.")) +
  tm_legend(position = c("right","bottom"))+
   tm_credits("Source: https://www.toronto.ca/city-government/data-research-maps/open-data/open-data-catalogue/ \n  wellbeing_toronto_2011.csv \n Analysis:Murali", position=c("right", "bottom"))
```

# Know Your Neighbourhood

### Mouse Over To Get Neighbourhood

````{r echo =FALSE}
map <- tm_shape(toronto_leaflet) +
   tm_polygons("MAP_COLORS", palette="Purples", alpha = .25) + 
 tm_borders(lwd=2, alpha = .25) +
  tm_layout("Neighbourhoods in Greater Toronto Area")
 lf <- tmap_leaflet(map)
 lf
```