EDUCATION

AGE

STATUS I

Row

Percentages Based Across Ontario

STATUS II

Row

Percentages Based Across Region

LAYOFF

Row

Layoff and Assists Across Region

---
title: "Employment Services Program "
output: 
  flexdashboard::flex_dashboard:
    source: embed
    
---

# Intro text {.sidebar}

Analysis presented here are based on dataset ES clients for each of the twenty-six Local Board (LB) areas in Ontario for the 2015/16 fiscal year. Please refer to Employment Ontario for  data  sources and method of collection.

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

```{r load, cache=TRUE}
Employment_Services_Data <- read_csv("Employment_Services_Program_Data_by_Local_Board_Area_FY1516.csv")

Employment_Services_Age_Data <- Employment_Services_Data %>%  select(EO_Region,Num_Assist,starts_with("Age"),starts_with("Edu"))

# sum the column by group  
ES_Age_Sum_Data <- Employment_Services_Age_Data %>% group_by(EO_Region) %>% 
                                                    summarise(Num_Assist = sum (Num_Assist), 
                                                              Age_15_24 = sum(Age_15_24),
                                                              Age_25_44 = sum(Age_25_44),
                                                              Age_45_64 = sum(Age_45_64),
                                                              Age_65_Plus = sum(Age_65_Plus),
                                                              Edu_8 = sum(Edu_8),
                                                              Edu_9_11 = sum(Edu_9_11),
                                                              Edu_Second = sum(Edu_Second),
                                                              Edu_Appr_Jrny = sum(Edu_Appr_Jrny),
                                                              Edu_College = sum(Edu_College),
                                                              Edu_Uni = sum(Edu_Uni),
                                                              Edu_Other = sum(Edu_Other))
# get the Grand Total of Num_Assist
grand_total_Num_Assist <-  as.numeric(ES_Age_Sum_Data %>% summarize(sum(Num_Assist)))

ES_Age_Sum_Data  <- ES_Age_Sum_Data %>% mutate( PNum_Assist = round( Num_Assist * 100 / grand_total_Num_Assist, 1),
                            PAge_15_24 = round( Age_15_24 * 100 / grand_total_Num_Assist, 1),  
                            PAge_25_44 = round( Age_25_44 *100 / grand_total_Num_Assist, 1),
                            PAge_45_64 = round( Age_45_64 * 100 / grand_total_Num_Assist, 1),  
                            PAge_65_Plus = round( Age_65_Plus * 100 / grand_total_Num_Assist, 1),  
                            PEdu_8 = round( Edu_8 * 100 / grand_total_Num_Assist, 1),   
                            PEdu_9_11 = round( Edu_9_11 * 100 / grand_total_Num_Assist, 1),   
                            PEdu_Second = round( Edu_Second *100 / grand_total_Num_Assist, 1),
                            PEdu_Appr_Jrny = round( Edu_Appr_Jrny *100 / grand_total_Num_Assist, 1),  
                            PEdu_College = round( Edu_College *100 / grand_total_Num_Assist, 1),  
                            PEdu_Uni = round( Edu_Uni *100 / grand_total_Num_Assist, 1),   
                            PEdu_Other = round( Edu_Other *100 / grand_total_Num_Assist, 1)) 

#______________

ES_Emp_Out_Data <- Employment_Services_Data %>%  select(EO_Region,Num_Assist,starts_with("Emp_Out"))

# Summarize by EO_Region
ES_Emp_Out_sum_Data <- ES_Emp_Out_Data %>% group_by(EO_Region) %>% 
                      summarise(Num_Assist = sum (Num_Assist), 
                                Emp_Out_FT      = sum(Emp_Out_FT),
                                Emp_Out_PT      = sum(Emp_Out_PT),
                                Emp_Out_SE      = sum(Emp_Out_SE),
                                Emp_Out_Emp_Edu = sum(Emp_Out_Emp_Edu),
                                Emp_Out_Emp_Tra = sum(Emp_Out_Emp_Tra),
                                Emp_Out_Appr    = sum(Emp_Out_Appr),
                                Emp_Out_Choice  = sum(Emp_Out_Choice),
                                Emp_Out_Suit    = sum(Emp_Out_Suit),
                                Emp_Out_Prof    = sum(Emp_Out_Prof)
                      )
# # sum the horizontal and vertical to varify                                                     )
 tmp <- ES_Emp_Out_sum_Data %>%  select( starts_with("Emp_Out")) 
# 
 VSums  <- rowSums(tmp, na.rm = TRUE)
 VGrandTotal <- sum(VSums, na.rm = TRUE)
  # 130673
  HSums <- colSums(tmp, na.rm = TRUE)
  HGrandTotal <- sum(HSums, na.rm = TRUE)
  # 130673
  # get the Grand Total of Num_Assist
  grand_total_Num_Assist <-  as.numeric(ES_Emp_Out_sum_Data %>% summarize(sum(Num_Assist)))
  
 # 194388
  conversionRate <- round(HGrandTotal / grand_total_Num_Assist , 1)
 # convert all "NA" values to 'zero'
  
  ES_Emp_Out_sum_Data[is.na(ES_Emp_Out_sum_Data)] <- 0

```

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

Row {data-height=350}
-----------------------------------------------------------------------

### Effect of Education


```{r}
ES_PEdu_Data <-  ES_Age_Sum_Data %>%  select(EO_Region,starts_with('PEdu_'))

# while suing rename: format to use new name = old name   
ES_PEdu_Data <- rename (ES_PEdu_Data,  Edu_8 = PEdu_8, Edu_9_11 = PEdu_9_11, Edu_Second  = PEdu_Second, Edu_Appr_Jrny = PEdu_Appr_Jrny, Edu_College = PEdu_College, Edu_Uni = PEdu_Uni, Edu_Other = PEdu_Other)  
ES_PEdu_Data_gather <-  ES_PEdu_Data %>% gather(2:8, key = "Education", value = "Percentage")

ES_PEdu_Data_gather$Education <-  ordered(ES_PEdu_Data_gather$Education, levels = c("Edu_8","Edu_Appr_Jrny","Edu_Other","Edu_9_11","Edu_Second","Edu_College","Edu_Uni" ))

ggplot(ES_PEdu_Data_gather, aes(Education,Percentage)) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        title = element_text(size = 15,face = "bold"),
        axis.title.x = element_text(size = 10),
        axis.title.y = element_text(size = 10)) +
  labs(
    title = "Educatinal Attainment of Clients",
    subtitle = "Percentages are based on Clients Served Across whole Ontario",
    caption = "Employment Ontario",
    x = "Level of Education") +
  geom_point(aes(color = Education)) +
  facet_grid(~EO_Region)

```

> Source: Employment Ontario : http://www.eo-geohub.com/datasets/employment-services-program-data-by-local-board-area-fy1516

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

Row {data-height=1000}
-----------------------------------------------------------------------


### Effect of Age

```{r}

ES_PAge_Data <-  ES_Age_Sum_Data %>%  select(EO_Region,starts_with('PAge_'))

# rename the columns
ES_PAge_Data <- rename (ES_PAge_Data,  Age_15_24 = PAge_15_24, Age_25_44 = PAge_25_44, Age_45_64 = PAge_45_64, Age_65_Plus = PAge_65_Plus)  

ES_PAge_Data_gather <-  ES_PAge_Data %>% gather(2:5, key = "Age", value = "Percentage")

ggplot(ES_PAge_Data_gather, aes(Age,Percentage)) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        title = element_text(size = 15,face = "bold"),
        axis.title.x = element_text(size = 10),
        axis.title.y = element_text(size = 10)) +
  labs(
    title = "Clients' Age Group",
    subtitle = "Percentages are based on Clients Served Across whole Ontario ",
    caption = "Employment Ontario",
    x = "Level of Education") +
  geom_point(aes(color = Age)) +
  facet_grid(~EO_Region)
```

> source: Service Area: https://www.arcgis.com/home/webmap/viewer.html?webmap=a1a2149aa4eb453bbcaaa8436feb117c

# STATUS I {data-icon="fa-map"}

Row {data-height=1000}
-----------------------------------------------------------------------


### Percentages Based Across Ontario

```{r}
  ES_Emp_Out_sum_Data  <- ES_Emp_Out_sum_Data %>%   mutate( 
    PEmp_Out_FT      = round (Emp_Out_FT * 100 / HGrandTotal, 1),
    PEmp_Out_PT      = round (Emp_Out_PT * 100 / HGrandTotal, 1),
    PEmp_Out_SE      = round (Emp_Out_SE * 100 / HGrandTotal, 1),
    PEmp_Out_Emp_Edu = round (Emp_Out_Emp_Edu * 100 / HGrandTotal, 1),
    PEmp_Out_Emp_Tra = round (Emp_Out_Emp_Tra * 100 / HGrandTotal, 1),
    PEmp_Out_Appr    = round (Emp_Out_Appr    * 100 / HGrandTotal, 1),
    EPmp_Out_Choice  = round (Emp_Out_Choice  * 100 / HGrandTotal, 1),
    PEmp_Out_Suit    = round (Emp_Out_Suit    * 100 / HGrandTotal, 1),
    PEmp_Out_Prof    = round (Emp_Out_Prof    * 100 / HGrandTotal, 1)    
  ) 
  
 

  ES_PEmp_Out_sum_Data <-  ES_Emp_Out_sum_Data %>%  select(EO_Region,starts_with('PEmp_'))
  
  # while suing rename: format to use new name = old name   
  ES_PEmp_Out_sum_Data <- rename (ES_PEmp_Out_sum_Data, Emp_Out_FT  = PEmp_Out_FT ,  Emp_Out_PT = PEmp_Out_PT,  Emp_Out_SE = PEmp_Out_SE,  Emp_Out_Emp_Edu = PEmp_Out_Emp_Edu, Emp_Out_Emp_Tra = PEmp_Out_Emp_Tra, Emp_Out_Appr = PEmp_Out_Appr, Emp_Out_Suit = PEmp_Out_Suit ) 
  
  
  ES_PEmp_Out_sum_Data_gather <-  ES_PEmp_Out_sum_Data %>% gather(2:8, key = "Employment", value = "Percentage")
  
  #ES_PEdu_Data_gather$Education <-  ordered(ES_PEdu_Data_gather$Education, levels = c("PEdu_8","PEdu_Appr_Jrny","PEdu_Other","PEdu_9_11","PEdu_Second","PEdu_College","PEdu_Uni" ))
  
  ggplot(ES_PEmp_Out_sum_Data_gather, aes(Employment,Percentage)) +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        title = element_text(size = 15,face = "bold"),
        axis.title.x = element_text(size = 10),
        axis.title.y = element_text(size = 10)) +
    labs(
      title = "Clients' Status of Employment on Exit",
      subtitle = "Percentages are based on Clients Served Across whole Ontario",
      caption = "Employment Ontario") +
    geom_point(aes(color = Employment)) +
    facet_grid(~EO_Region) 
```

# STATUS II {data-icon="fa-map"}

Row {data-height=1000}
-----------------------------------------------------------------------

### Percentages Based Across Region

```{r}
# Get the percentage based on regional total  
  ES_Percnt_Local_Emp_Out  <- ES_Emp_Out_sum_Data %>%   mutate( 
    PEmp_Out_FT      = round (Emp_Out_FT * 100 / VSums, 1),
    PEmp_Out_PT      = round (Emp_Out_PT * 100 / VSums, 1),
    PEmp_Out_SE      = round (Emp_Out_SE * 100 / VSums, 1),
    PEmp_Out_Emp_Edu = round (Emp_Out_Emp_Edu * 100 / VSums, 1),
    PEmp_Out_Emp_Tra = round (Emp_Out_Emp_Tra * 100 / VSums, 1),
    PEmp_Out_Appr    = round (Emp_Out_Appr    * 100 / VSums, 1),
    EPmp_Out_Choice  = round (Emp_Out_Choice  * 100 / VSums, 1),
    PEmp_Out_Suit    = round (Emp_Out_Suit    * 100 / VSums, 1),
    PEmp_Out_Prof    = round (Emp_Out_Prof    * 100 / VSums, 1)
    
  ) 
  
   ES_Percnt_Local_Emp_Out <- ES_Percnt_Local_Emp_Out %>%  select(EO_Region,starts_with('PEmp_'))

# while suing rename: format to use new name = old name   
   ES_Percnt_Local_Emp_Out <- rename (ES_Percnt_Local_Emp_Out, Emp_Out_FT  = PEmp_Out_FT ,  Emp_Out_PT = PEmp_Out_PT,  Emp_Out_SE = PEmp_Out_SE,  Emp_Out_Emp_Edu = PEmp_Out_Emp_Edu, Emp_Out_Emp_Tra = PEmp_Out_Emp_Tra, Emp_Out_Appr = PEmp_Out_Appr, Emp_Out_Suit = PEmp_Out_Suit ) 
   
   ES_Percnt_Local_Emp_Out_gather <-  ES_Percnt_Local_Emp_Out %>% gather(2:8, key = "Employment", value = "Percentage")
  
  #ES_PEdu_Data_gather$Education <-  ordered(ES_PEdu_Data_gather$Education, levels = c("PEdu_8","PEdu_Appr_Jrny","PEdu_Other","PEdu_9_11","PEdu_Second","PEdu_College","PEdu_Uni" ))
   
  
 ggplot(ES_Percnt_Local_Emp_Out_gather, aes(Employment,Percentage)) +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        title = element_text(size = 15,face = "bold"),
        axis.title.x = element_text(size = 10),
        axis.title.y = element_text(size = 10)) +
    labs(
      title = "Clients' Status of Employment on Exit",
      subtitle = "Percentages based on Clients Served by Regional Service Centers",
      caption = "Employment Ontario") +
    geom_point(aes(color = Employment)) +
    facet_grid(~EO_Region)
```

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

Row {data-height=1000}
-----------------------------------------------------------------------

### Layoff and Assists Across Region

```{r}
ES_Layoff_Data <- Employment_Services_Data %>%  select(EO_Region,starts_with("Layoff"))

# convert all "NA" values to 'zero'
ES_Layoff_Data[is.na(ES_Layoff_Data)] <- 0

# sum the column by group  
ES_Layoff_Ind_Sum_Data <- ES_Layoff_Data %>% group_by(EO_Region) %>%
                                        summarise(
                                                  Layoff_Ind_72 = sum(Layoff_Ind_72),
                                                  Layoff_Ind_56 = sum(Layoff_Ind_56),
                                                  Layoff_Ind_11 = sum(Layoff_Ind_11),
                                                  Layoff_Ind_71 = sum(Layoff_Ind_71),
                                                  Layoff_Ind_23 = sum(Layoff_Ind_23),
                                                  Layoff_Ind_61 = sum(Layoff_Ind_61),
                                                  Layoff_Ind_52 = sum(Layoff_Ind_52),
                                                  Layoff_Ind_62 = sum(Layoff_Ind_62),
                                                  Layoff_Ind_51 = sum(Layoff_Ind_51),
                                                  Layoff_Ind_55 = sum(Layoff_Ind_55),
                                                  Layoff_Ind_31 = sum(Layoff_Ind_31),
                                                  Layoff_Ind_21 = sum(Layoff_Ind_21),
                                                  Layoff_Ind_81 = sum(Layoff_Ind_81),
                                                  Layoff_Ind_54 = sum(Layoff_Ind_54),
                                                  Layoff_Ind_91 = sum(Layoff_Ind_91),
                                                  Layoff_Ind_53 = sum(Layoff_Ind_53),
                                                  Layoff_Ind_44 = sum(Layoff_Ind_44),
                                                  Layoff_Ind_48 = sum(Layoff_Ind_48),
                                                  Layoff_Ind_22 = sum(Layoff_Ind_22),
                                                  Layoff_Ind_41 = sum(Layoff_Ind_41)
                                                  )



ES_Layoff_Occ_Sum_Data <- ES_Layoff_Data %>% group_by(EO_Region) %>%
  summarise(
            Layoff_Occ_12 = sum(Layoff_Occ_12),
            Layoff_Occ_95 = sum(Layoff_Occ_95),
            Layoff_Occ_34 = sum(Layoff_Occ_34),
            Layoff_Occ_44 = sum(Layoff_Occ_44),
            Layoff_Occ_15 = sum(Layoff_Occ_15),
            Layoff_Occ_13 = sum(Layoff_Occ_13),
            Layoff_Occ_86 = sum(Layoff_Occ_86),
            Layoff_Occ_72 = sum(Layoff_Occ_72),
            Layoff_Occ_96 = sum(Layoff_Occ_96),
            Layoff_Occ_73 = sum(Layoff_Occ_73),
            Layoff_Occ_06 = sum(Layoff_Occ_06),
            Layoff_Occ_07 = sum(Layoff_Occ_07),
            Layoff_Occ_43 = sum(Layoff_Occ_43),
            Layoff_Occ_14 = sum(Layoff_Occ_14),
            Layoff_Occ_74 = sum(Layoff_Occ_74),
            Layoff_Occ_42 = sum(Layoff_Occ_42),
            Layoff_Occ_94 = sum(Layoff_Occ_94),
            Layoff_Occ_92 = sum(Layoff_Occ_92),
            Layoff_Occ_51 = sum(Layoff_Occ_51),
            Layoff_Occ_11 = sum(Layoff_Occ_11),
            Layoff_Occ_40 = sum(Layoff_Occ_40),
            Layoff_Occ_31 = sum(Layoff_Occ_31),
            Layoff_Occ_41 = sum(Layoff_Occ_41),
            Layoff_Occ_21 = sum(Layoff_Occ_21),
            Layoff_Occ_30 = sum(Layoff_Occ_30),
            Layoff_Occ_62 = sum(Layoff_Occ_62),
            Layoff_Occ_64 = sum(Layoff_Occ_64),
            Layoff_Occ_66 = sum(Layoff_Occ_66),
            Layoff_Occ_00 = sum(Layoff_Occ_00),
            Layoff_Occ_65 = sum(Layoff_Occ_65),
            Layoff_Occ_63 = sum(Layoff_Occ_63),
            Layoff_Occ_67 = sum(Layoff_Occ_67),
            Layoff_Occ_01 = sum(Layoff_Occ_01),
            Layoff_Occ_82 = sum(Layoff_Occ_82),
            Layoff_Occ_52 = sum(Layoff_Occ_52),
            Layoff_Occ_32 = sum(Layoff_Occ_32),
            Layoff_Occ_22 = sum(Layoff_Occ_22),
            Layoff_Occ_76 = sum(Layoff_Occ_76),
            Layoff_Occ_75 = sum(Layoff_Occ_75),
            Layoff_Occ_84 = sum(Layoff_Occ_84)
            )

# # # sum the horizontal and vertical to varify                                                     )
 tmp_Ind <- ES_Layoff_Ind_Sum_Data %>%  select( starts_with("Layoff")) 
 tmp_Occ <- ES_Layoff_Occ_Sum_Data %>%  select( starts_with("Layoff")) 
# 
VSums_Ind  <- rowSums(tmp_Ind, na.rm = TRUE)
VGrandTotal_Ind <- sum(tmp_Ind, na.rm = TRUE)
# 111362
HSums_Ind <- colSums(tmp_Ind, na.rm = TRUE)
HGrandTotal_ind <- sum(HSums_Ind, na.rm = TRUE)
# 111362

VSums_Occ  <- rowSums(tmp_Occ, na.rm = TRUE)
VGrandTotal_Occ <- sum(VSums_Occ, na.rm = TRUE)
# 111362
HSums_Occ <- colSums(tmp_Occ, na.rm = TRUE)
HGrandTotal_Occ <- sum(HSums_Occ, na.rm = TRUE) 
# 111362

# Get region, assist, non assist
ES_Assist_Data <- Employment_Services_Data %>%  select(EO_Region,Num_Assist,Num_Unassist)

# sum the column by group  
ES_Assist_Sum_Data <- ES_Assist_Data %>% group_by(EO_Region) %>%
  summarise( Num_Assist = sum(Num_Assist), 
             Num_Unassist = sum(Num_Unassist)
            )



df_to_plot <-  tibble(
                       Region = ES_Layoff_Ind_Sum_Data$EO_Region,
                       Unassist = ES_Assist_Sum_Data$Num_Unassist,
                       Assist = ES_Assist_Sum_Data$Num_Assist,
                       Industry = VSums_Ind,
                       Occupation = VSums_Occ
                       
)

df_to_plot_gather <-  df_to_plot %>% gather(2:5, key = "Groups", value = "Count")
df_to_plot_gather$Region <-  ordered(df_to_plot_gather$Region, levels = c("Central",  "Western", "Eastern",  "Northern"   ))


 ggplot(df_to_plot_gather, aes(x=Region, y=Count)) + 
  geom_line(aes(colour=Groups, group=Groups),  lwd = 1.0) + # colour, group both depend on cond2
  geom_point(aes(colour=Groups), size=2) +             # colour depends on cond2
                         # larger points, different shape
  labs(title = "Number of Assist and Layoff Across Regions") +
  labs(y = "Counts", x= "Regions")
```