knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of clccommunities is to make it easy to identify postal codes in low income or rural communities.
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")
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()
# 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)
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()
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")
June 2021 Ontario Public School Address File
2016 Geographic Attribute File
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.