This is an static line plot created in ggplot2
This is an interactive line plot created in plotly.
Different regions can be removed or added by clicking on their icon in the legend
A region can be isolated by double-clicking on their icon in the legend
This is a static map of the unemployment rate in Ontario based on Statcan data.
Per the data the unemployment rate for
2025-04-01 is 7.6
2024-04-01 is 6.7
This interactive map shows how the leaflet tool allows for creating multiple layers that can be toggled on and off. In this case, we have the Unemployment rate and the participation rate.
---
title: "Unemployment in Ontario"
output:
flexdashboard::flex_dashboard:
storyboard: true
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse) # Package that allows for the use of tidy syntax
library(cansim) # Package that allows for the download of statcan tables into R from their catalog number
library(sf) # Allows for the use of spatial objects
library(leaflet) # Allows for the use of interactive spatial objects
library(ggspatial) # Utility for north arrow and scale bar in static R maps
library(plotly) # Utility
Labourforce_survey <- get_cansim("14-10-0462-01") # Download latest labour force survey results from StatCan
Ontario_Map <- read_sf("Ontario_ER.gpkg") # Load ER map of Ontario
Current_date <- max(Labourforce_survey$Date) # Calculate latest date in the Labour Force Survey
last_year <- Current_date - years(1) # Calculate last year from latest date
Ontario_Current_Unemployment <- Labourforce_survey |> # Filter Labourforce Survey to pull the unemployment value
filter(GEO == "Ontario") |> # for most recent date for the geography of Ontario
filter(Statistics == "Estimate") |>
filter(`Labour force characteristics` == "Unemployment rate") |>
filter(Date == Current_date) |>
pull(VALUE)
Ontario_Current_Unemployment_last_year <- Labourforce_survey |> # Filter Labourforce Survey to pull the unemployment value for
filter(GEO == "Ontario") |> # for last year's date for the geography of Ontario
filter(Statistics == "Estimate") |>
filter(`Labour force characteristics` == "Unemployment rate") |>
filter(Date == last_year) |>
pull(VALUE)
Ontario_Labourforce_Current_UR <- Labourforce_survey |> # Filter Labourforce Survey to pull the unemployment value
semi_join(Ontario_Map) |> # Use semi-join (AKA Filtering join) to extract Ontario's 11 ERs
filter(Statistics == "Estimate") |>
filter(`Labour force characteristics` == "Unemployment rate") |>
filter(Date == Current_date)
Ontario_Labourforce_Current_PR <- Labourforce_survey |> # Filter Labourforce Survey to pull the participation rate value
semi_join(Ontario_Map) |>
filter(Statistics == "Estimate") |>
filter(`Labour force characteristics` == "Participation rate") |>
filter(Date == Current_date)
Ontario_interactive_map_data <- Ontario_Labourforce_Current_PR |> # Splice unemployment rate and particiation rate into one dataframe
mutate(Participation_rate = VALUE) |>
select(3,4,5,25) |>
left_join(Ontario_Labourforce_Current_UR[,c(4,8)]) |>
mutate(Unemployment_rate = VALUE) |>
select(-5)
```
### Static Line Graph.
```{r Static_Graph, fig.height=10, fig.width=25, message=FALSE, warning=FALSE, paged.print=FALSE}
Ontario_Unemployment <- Labourforce_survey |>
filter(GeoUID > 3500 & GeoUID < 3600) |>
filter(Statistics == "Estimate") |>
filter(`Labour force characteristics` == "Unemployment rate") |>
ggplot(aes(x = Date, y = VALUE, colour = GEO)) +
geom_line() +
labs(
title = "Unemployment in Ontario by ER",
subtitle = paste0("Data as of: ", Current_date),
caption = paste0("Compiled on 2025-04-09 from StatCan table 14-10-0462-01
By Strategic Initiatives Branch
Ministry of Northern Economic Development and Growth" )
) +
ylab("Unemployment Rate")
Ontario_Unemployment
```
------------------------------------------------------------------------
This is an static line plot created in ggplot2
### Interactive Line Graph.
```{r Interactive_Graph, fig.height=10, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE}
Ontario_Unemployment <- Labourforce_survey |>
filter(GeoUID > 3500 & GeoUID < 3600) |>
filter(Statistics == "Estimate") |>
filter(`Labour force characteristics` == "Unemployment rate") |>
ggplot(aes(x = Date, y = VALUE, colour = GEO)) +
geom_line() +
labs(
title = "Unemployment in Ontario by ER",
subtitle = paste0("Data as of: ", Current_date),
caption = paste0("Compiled on 2025-04-09 from StatCan table 14-10-0462-01
By Strategic Initiatives Branch
Ministry of Northern Economic Development and Growth" )
) +
ylab("Unemployment Rate")
ggplotly(Ontario_Unemployment) # ggplotly is a wrapper application that converts select elements of a GGplot2 graph into a java-based interactive html element
```
------------------------------------------------------------------------
This is an interactive line plot created in plotly.
- Different regions can be removed or added by clicking on their icon in the legend
- A region can be isolated by double-clicking on their icon in the legend
### Static Map of Unemployment in Ontario by ER.
```{r Static_Map, fig.height=10, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE}
Labourforce_static_Map <- Ontario_Map |>
inner_join(Ontario_Labourforce_Current_UR) |>
ggplot() +
geom_sf(aes(fill = VALUE)) +
labs(
title = "Map of Unemployment in Ontario by ER",
subtitle = paste0("Data as of: ", Current_date),
caption = paste0("Compiled on 2025-04-09 from StatCan table 14-10-0462-01
By Strategic Initiatives Branch
Ministry of Northern Economic Development and Growth" )
) +
annotation_scale(location = "bl", width_hint = 0.5) + # Adds the scale bar
annotation_north_arrow( # Adds the North Arrow
location = "bl",
which_north = "true",
pad_x = unit(0.75, "in"),
pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering
)
Labourforce_static_Map
```
------------------------------------------------------------------------
This is a static map of the unemployment rate in Ontario based on Statcan data.
Per the data the unemployment rate for
- `r Current_date` is `r Ontario_Current_Unemployment`
- `r last_year` is `r Ontario_Current_Unemployment_last_year`
### Interactive Map of Unemployment and Participation Rates.
```{r Interactive Map}
#### This map is doubly inter-active thanks to the java-based applet leaflet.
#### This applet allows the user to add points and polygons on top of a basemap.
#### The default is open street map, but there are options to choose other base
#### wwwwwwwwwdmaps like google maps and statmaps
####
#### The first level of interaction is that the map can pan and zoom in
#### The second level of interaction is that different layers can be overlapped.
#### - Not limited to polygons. Can be done with points, pushpins, icons...
#### The objects can also contain tool tips if the object is clicked on.
map_Ontario_ER <- Ontario_Map %>%
left_join(Ontario_interactive_map_data) |>
st_transform(crs = 4326)
ON_UP <- colorNumeric(palette = "viridis", domain = map_Ontario_ER$Unemployment_rate) # Sets the colour pallet with the Viridis pallet
ON_PR <- colorNumeric(palette = "viridis", domain = map_Ontario_ER$Participation_rate) # Sets the colour pallet with the Viridis pallet
leaflet() %>%
addTiles() %>%
setView(lng = -85, lat = 50, zoom = 5) %>%
addPolygons(data = map_Ontario_ER, fillColor = ~ON_UP(Unemployment_rate), stroke = TRUE, color = "#000000", weight = 0.25, fillOpacity = 0.5,
popup = ~paste0(ERNAME, "<hr>","Unemployment Rate:", Unemployment_rate), group = "Unemployment Rate") %>%
addPolygons(data = map_Ontario_ER, fillColor = ~ON_PR(Participation_rate), stroke = TRUE, color = "#000000", weight = 0.25, fillOpacity = 0.5,
popup = ~paste0(ERNAME, "<hr>","Participation Rate:", Participation_rate), group = "Participation Rate") %>%
addLayersControl(baseGroups = c("Base Map"), overlayGroups = c("Unemployment Rate", "Participation Rate"),
position = "topright")
```
------------------------------------------------------------------------
This interactive map shows how the leaflet tool allows for creating multiple layers that can be toggled on and off. In this case, we have the Unemployment rate and the participation rate.