knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

clccommunities

The goal of clccommunities is to make it easy to identify postal codes in low income or rural communities.

Installation

You can install the latest version of the clccommunities package from GitHub.

# Run this line once to install the devtools package
# install.packages("devtools") 

# Run this line once to install or update the clccommunities package
devtools::install_github("context-dependent/clccommunities")

Define Low Income and Rural Communities in Existing Data

library(tidyverse)
library(clccommunities)
## basic example code

ontario_schools_plus <- ontario_schools %>% 

  mutate(
    clc_low_income = clc_calculate_low_income(postal_code), 
    clc_rural = clc_calculate_rural(postal_code)
  )

ontario_schools_plus %>% 
  count(clc_low_income) %>% 
  knitr::kable()

ontario_schools_plus %>% 
  count(clc_rural) %>% 
  knitr::kable()

Add All Columns from the Reference Dataset to Existing Data

# Run this once to install the tidyverse family of packages.
# install.packages("tidyverse")

library(tidyverse)
library(clccommunities)

ontario_schools_community_data <- add_community_data(ontario_schools, postal_code)

# Run this once to install the skimr package (not necessary, but helpful in general)
# install.packages("skimr")

skimr::skim_without_charts(ontario_schools_community_data)

Making a Simple Choropleth

FSA polygons are available in the fsa_shp package data. The initial installation process for the sf (Simple Features) package is slightly more involved than the process for the other packages used in these examples. You will need to first install the geospatial libraries that sf interfaces with on your computer.

library(sf)
library(tidyverse)
library(clccommunities)

schools_per_fsa <- ontario_schools %>% 

  add_community_data(postal_code) %>% 
  group_by(fsa) %>% 
  summarize(
    n_schools = n()
  )

schools_per_fsa_shp <- fsa_shp %>% 

  left_join(fsa_data, by = "fsa") %>% 
  filter(province == "Ontario") %>% 
  left_join(schools_per_fsa, by = "fsa") %>% 
  mutate(
    n_schools = coalesce(n_schools, 0)
  )

n_schools_range <- range(schools_per_fsa_shp$n_schools)

schools_per_fsa_shp %>% 

  ggplot() + 
  geom_sf(aes(fill = n_schools), colour = NA) + 
  scale_fill_viridis_b(
    guide = guide_colorbar(
      title = "# of Schools", 
      barheight = 12, 
      barwidth = 0.5
    ), 
    breaks = seq(0, 65, by = 10)
  ) + 
  theme_void() 

Using package data outside of R

To use these data outside of the R environment, write the fsa_data object to a csv file, which you can open in Excel, Google Sheets, or any other program.

library(readr)
library(clccommunities)

write_csv(fsa_data, "path/to/destination-folder/file-name-of-your-choice.csv")

Data Sources

June 2021 Ontario Public School Address File

2016 Census Profiles

2016 Census Boundary Files

2016 Geographic Attribute File



context-dependent/clccommunities documentation built on Jan. 21, 2022, 2:33 a.m.