TP

Row

Per Capita Cost increases while Crime is down !!

Source: Per Capita Cost (Cdn$) : http://www.torontopolice.on.ca/publications/#reports Uniform Strength / 100,000 population : http://www.torontopolice.on.ca/publications/#reports Incident-based crime statistics, by detailed violations and police services, Ontario incident per 100,000 http://www5.statcan.gc.ca/cansim/a26?lang=eng&retrLang=eng&id=2520077&pattern=Incident-based+crime+statistics%2C+by+detailed+violations+and+police+services%2C+Ontario&tabMode=dataTable&srchLan=-1&p1=1&p2=49

---
title: " Toronto Police "
output: 
  flexdashboard::flex_dashboard:
    source: embed
    
---

# Intro text {.sidebar}

“Toronto Police Chief Mark Saunders doesn't buy the idea that officers are burned out.” NEWTALK1010
“Low morale prompts exodus of officers: Toronto Police Association” The SUN
Analysis here shows per capita cost for a uniformed police officer going up while the crime is down.  Since the crime is down, officers may be leaving the force for more exciting opportunities!

```{r setup, include=FALSE}
library(tidyverse)
library(readr)
 knitr::opts_chunk$set(fig.width = 10, fig.asp = 1/2) 
```

```{r load, cache=TRUE}

df_original <- read_csv("cansim-2520077-eng-1986415304632774828.csv", 
                                                   skip = 3)

# select only the row for Toronto and columns 3 to 21
# Total violations minus cleared charges
Totalviolations <- df_original[4,c(3:21)]
Totalviolations <- as.data.frame(t(Totalviolations))


# insert a column with row names
Totalviolations$Year <- rownames(Totalviolations)  

colnames(Totalviolations) <- c("Violation_Per_100000_POP",  "Year")

df_TV <- Totalviolations[2:19,]

# convert factor values into character before converting into numeric
df_TV$Violation_Per_100000_POP <-  as.numeric(as.character(df_TV$Violation_Per_100000_POP))

# police Data
TorontoPolice <- read_delim("TorontoPolice.txt", 
                            " ", escape_double = FALSE, trim_ws = TRUE)

TorontoPolice_Transpose <- as.data.frame(t(TorontoPolice)) 

# insert a column with row names
TorontoPolice_Transpose$Year <- rownames(TorontoPolice_Transpose)  

# col_names <- TorontoPolice_Transpose[1,]
# change the column names
colnames(TorontoPolice_Transpose) <- c("Population", "PerCapitaCost", "PopulationPerUniformStrength", "Year")


# remove the first row
df_TP <- TorontoPolice_Transpose[2:21,]


df_TP$Population <-  as.numeric( as.character( df_TP$Population ))
df_TP$PerCapitaCost <- as.numeric( as.character( df_TP$PerCapitaCost ))
df_TP$PopulationPerUniformStrength <- as.numeric( as.character( df_TP$PopulationPerUniformStrength))


df_TP_TV <-   inner_join(df_TP,df_TV, by = "Year")

df_TP_TV  <- df_TP_TV %>%  mutate( UniformStrength_Per_100000_POP = round( 100000 / PopulationPerUniformStrength, 1 ))

df_to_gather <-  df_TP_TV  %>%  select(Year,PerCapitaCost, Violation_Per_100000_POP,UniformStrength_Per_100000_POP)

colnames(df_to_gather) <-  c("Year","PerCapitaCost","Violations_Per_Hundredthousand","UniformStrength_Per_Hundredthousand")

df_to_plot <- df_to_gather %>% gather(key = "Type", value = "value",2:4)


```

# TP {data-icon="fa-map"}

Row {data-height=600}
-----------------------------------------------------------------------

### Per Capita Cost increases while Crime is down !! 

```{r}
label <- tibble(
  Year = Inf,
  value = Inf,
  label = "Per capita cost increases with reduction of unifrom strength and reported violations !!!"
)
ggplot(df_to_plot,aes(x = Year, y = value, group = 1)) +
  
  geom_point(shape = 1) +  
  #geom_smooth() +
  
  geom_line() +
  geom_text(aes(label = label), data = label, vjust = "top", hjust = "right", color = "red") +
  facet_grid(Type ~ .,scales = "free_y") +
  labs(y = " Violations/100,000       Uniform Strength / 100,000       Per Capita Cost ($) ") +
  labs(title = "Toronto Police") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, vjust = 0.5, size = 7),axis.text.y = element_text(size = 7)) 

```


> Source: Per Capita Cost (Cdn$) : http://www.torontopolice.on.ca/publications/#reports
Uniform Strength / 100,000 population : http://www.torontopolice.on.ca/publications/#reports
Incident-based crime statistics, by detailed violations and police services, Ontario incident per 100,000
http://www5.statcan.gc.ca/cansim/a26?lang=eng&retrLang=eng&id=2520077&pattern=Incident-based+crime+statistics%2C+by+detailed+violations+and+police+services%2C+Ontario&tabMode=dataTable&srchLan=-1&p1=1&p2=49