{"id":16284773,"url":"https://github.com/pachadotdev/canadamaps","last_synced_at":"2025-07-26T21:34:53.754Z","repository":{"id":56934366,"uuid":"365280386","full_name":"pachadotdev/canadamaps","owner":"pachadotdev","description":"Maps of the Political and Administrative Divisions of Canada.","archived":false,"fork":false,"pushed_at":"2024-03-24T22:08:24.000Z","size":23300,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-02T05:07:04.611Z","etag":null,"topics":["canada","maps"],"latest_commit_sha":null,"homepage":"https://pacha.dev/canadamaps","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pachadotdev.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json"},"funding":{"custom":["https://www.buymeacoffee.com/pacha"]}},"created_at":"2021-05-07T15:40:40.000Z","updated_at":"2024-03-27T04:29:43.000Z","dependencies_parsed_at":"2022-08-21T06:50:38.252Z","dependency_job_id":"81e84413-fe60-453e-b735-c684305fd377","html_url":"https://github.com/pachadotdev/canadamaps","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.3571428571428571,"last_synced_commit":"416b6d512b8bf9354a76a93392c5e62604715ee9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fcanadamaps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fcanadamaps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fcanadamaps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pachadotdev%2Fcanadamaps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pachadotdev","download_url":"https://codeload.github.com/pachadotdev/canadamaps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247279333,"owners_count":20912866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["canada","maps"],"created_at":"2024-10-10T19:20:50.889Z","updated_at":"2025-04-05T02:30:54.714Z","avatar_url":"https://github.com/pachadotdev.png","language":"R","funding_links":["https://www.buymeacoffee.com/pacha"],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/pachadotdev/canadamaps/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pachadotdev/canadamaps/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n  \n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# canadamaps\n\n## General idea\n\nThe idea is to avoid \"duplications\", for example instead of adding a provinces \nmap or others, we provide functions to sum Census Divisions in all possible \ncases.\n\n```{r general, message=FALSE, warning=FALSE}\nlibrary(ggplot2)\nlibrary(canadamaps)\n\nggplot(data = census_divisions) +\n  geom_sf(aes(geometry = geometry)) +\n  labs(title = \"Canada's Census Divisions\")\n```\n\nThe same idea can be applied to other maps with different levels of aggregation.\n\n```{r other_maps, eval=FALSE}\nggplot(data = get_agricultural_divisions()) +\n  geom_sf(aes(geometry = geometry)) +\n  labs(title = \"Canada's Census Agricultural Regions\")\n\nggplot(data = get_economic_regions()) +\n  geom_sf(aes(geometry = geometry)) +\n  labs(title = \"Canada's Economic Regions\")\n\nggplot(data = federal_electoral_districts) +\n  geom_sf(aes(geometry = geometry)) +\n  labs(title = \"Canada's Federal Electoral Districts\")\n\nggplot(data = get_provinces()) +\n  geom_sf(aes(geometry = geometry)) +\n  labs(title = \"Canada's Provinces\")\n```\n\n## Lambert projection\n\nWe can change the CRS with the sf package but please read the explanation from [Stats Canada](https://www150.statcan.gc.ca/n1/pub/92-195-x/2011001/other-autre/mapproj-projcarte/m-c-eng.htm).\n\n```{r lambert, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}\n# shortcut function to change the CRS\ncensus_divisions \u003c- lambert_projection(census_divisions)\n\nggplot(data = census_divisions) +\n  geom_sf(aes(geometry = geometry)) +\n  labs(title = \"Canada's Census Divisions\")\n```\n\n## Using real data\n\nLet's say I want to replicate the map from [Health Canada](https://health-infobase.canada.ca/covid-19/vaccination-coverage/), which was checked on 2023-08-02 and was updated up to 2024-02-25. To do this, I need to download the [CSV file](https://health-infobase.canada.ca/src/data/covidLive/vaccination-coverage-map.csv) from Health Canada and then combine it with the provinces map from canadamaps.\n\n```{r covid_map, warning=FALSE, message=FALSE}\nlibrary(readr)\nlibrary(dplyr)\nlibrary(sf)\n\nurl \u003c- \"https://health-infobase.canada.ca/src/data/covidLive/vaccination-coverage-map.csv\"\ncsv \u003c- paste0(\"data_processing/\", gsub(\".*/\", \"\", url))\nif (!file.exists(csv)) download.file(url, csv)\n\nvaccination \u003c- read_csv(csv, col_types = cols(prop5plus_atleast1dose = col_character())) %\u003e%\n  filter(week_end == as.Date(\"2024-02-25\"), pruid != 1) %\u003e%\n  select(pruid, proptotal_atleast1dose) %\u003e%\n  mutate(\n    proptotal_atleast1dose = as.numeric(case_when(\n      proptotal_atleast1dose == \"\u003e=99\" ~ 99,\n      TRUE ~ proptotal_atleast1dose\n    ))\n  )\n\nvaccination \u003c- vaccination %\u003e%\n  inner_join(get_provinces(), by = \"pruid\") %\u003e% # canadamaps in action\n  mutate(\n    label = paste(gsub(\" /.*\", \"\", prname),\n      paste0(proptotal_atleast1dose, \"%\"),\n      sep = \"\\n\"\n    ),\n  )\n```\n\nAn initial plot can be done with the following code.\n\n```{r covid_map_2, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}\n# colours obtained with Chromium's inspector\ncolours \u003c- c(\"#efefa2\", \"#c2e699\", \"#78c679\", \"#31a354\", \"#006837\")\n\nggplot(vaccination) +\n  geom_sf(aes(fill = proptotal_atleast1dose, geometry = geometry)) +\n  geom_sf_label(aes(label = label, geometry = geometry)) +\n  scale_fill_gradientn(colours = colours, name = \"Cumulative percent\") +\n  labs(title = \"Cumulative percent of the population who have received at least 1 dose of a COVID-19 vaccine\") +\n  theme_minimal(base_size = 13)\n```\n\nWe can use different ggplot themes.\n\n```{r covid_map_3, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}\nggplot(vaccination) +\n  geom_sf(aes(fill = proptotal_atleast1dose, geometry = geometry)) +\n  geom_sf_label(aes(label = label, geometry = geometry)) +\n  scale_fill_gradientn(colours = colours, name = \"Cumulative percent\") +\n  labs(title = \"Cumulative percent of the population who have received at least 1 dose of a COVID-19 vaccine\") +\n  theme_void() +\n  theme(\n    legend.position = \"top\",\n    plot.title = element_text(hjust = 0.5)\n  )\n```\n\nIf we want to fill the information for Alberta, which is not seen in the original map, we can fill and then filter.\n\n```{r covid_map_4, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}\nlibrary(tidyr)\n\nvaccination \u003c- read_csv(csv, col_types = cols(prop5plus_atleast1dose = col_character())) %\u003e%\n  arrange(pruid, week_end) %\u003e%\n  group_by(pruid) %\u003e%\n  fill(proptotal_atleast1dose, .direction = \"down\") %\u003e% # Alberta is filled with an older value\n  filter(week_end == as.Date(\"2024-02-25\"), pruid != 1) %\u003e%\n  select(pruid, proptotal_atleast1dose) %\u003e%\n  mutate(\n    proptotal_atleast1dose = as.numeric(case_when(\n      proptotal_atleast1dose == \"\u003e=99\" ~ 99,\n      TRUE ~ proptotal_atleast1dose\n    ))\n  ) %\u003e%\n  inner_join(get_provinces(), by = \"pruid\") %\u003e% # canadamaps in action\n  mutate(\n    label = paste(gsub(\" /.*\", \"\", prname),\n      paste0(proptotal_atleast1dose, \"%\"),\n      sep = \"\\n\"\n    ),\n  ) %\u003e%\n  lambert_projection()\n\nggplot(vaccination) +\n  geom_sf(aes(fill = proptotal_atleast1dose, geometry = geometry)) +\n  geom_sf_label(aes(label = label, geometry = geometry)) +\n  scale_fill_gradientn(colours = colours, name = \"Cumulative percent\") +\n  labs(title = \"Cumulative percent of the population who have received at least 1 dose of a COVID-19 vaccine\") +\n  theme_minimal(base_size = 13)\n```\n\n## Units of aggregation\n\n### Census Division\n\nThe finest division in this package is the Census Division (CDs) which can be\nof the next types (reference: https://www.statcan.gc.ca/en/subjects/standard/sgc/2011/sgc-tab-d).\n\n|Language form of CD type|Abbreviation for English language publications|Title for English language publications|Abbreviation for French language publications|Title for French language publications|Abbreviation for bilingual publications|Title for bilingual publications         |\n|------------------------|----------------------------------------------|---------------------------------------|---------------------------------------------|--------------------------------------|---------------------------------------|-----------------------------------------|\n|Bilingual               |CDR                                           |Census division                        |CDR                                          |Division de recensement               |CDR                                    |Census division / Division de recensement|\n|Bilingual               |CT                                            |County                                 |CT                                           |Comté                                 |CT                                     |County / Comté                           |\n|English only            |CTY                                           |County                                 |CTY                                          |County                                |CTY                                    |County                                   |\n|English only            |DIS                                           |District                               |DIS                                          |District                              |DIS                                    |District                                 |\n|English only            |DM                                            |District municipality                  |DM                                           |District municipality                 |DM                                     |District municipality                    |\n|French only             |MRC                                           |Municipalité régionale de comté        |MRC                                          |Municipalité régionale de comté       |MRC                                    |Municipalité régionale de comté          |\n|English only            |RD                                            |Regional district                      |RD                                           |Regional district                     |RD                                     |Regional district                        |\n|English only            |REG                                           |Region                                 |REG                                          |Region                                |REG                                    |Region                                   |\n|English only            |RM                                            |Regional municipality                  |RM                                           |Regional municipality                 |RM                                     |Regional municipality                    |\n|French only             |TÉ                                            |Territoire équivalent                  |TÉ                                           |Territoire équivalent                 |TÉ                                     |Territoire équivalent                    |\n|Bilingual               |TER                                           |Territory                              |TER                                          |Territoire                            |TER                                    |Territory / Territoire                   |\n|English only            |UC                                            |United counties                        |UC                                           |United counties                       |UC                                     |United counties                          |\n\nThe division type is specified in the `census_divisions` table.\n\n### Census Agricultural Regions\n\nCensus Agricultural Regions (CARs) can be obtained as sums of CDs. Excluding\nsome special cases for Northwestern Territories, Nunavur and Yukon that we\nclarified over email communication, the source to match CDs to CARs was obtained\nfrom [Census of Agriculture Reference Maps](https://www150.statcan.gc.ca/n1/pub/95-630-x/95-630-x2017000-eng.htm)\nand manually organized in a spreadsheet (https://github.com/pachadotdev/canadamaps/tree/main/data_xlsx).\n\n### Economic Regions\n\nEconomic Regions (ERs) can be obtained as sums of CDs. The only special case is\nthe Halton, which belongs to two economic zones and it's the only CD that has\nto be carefully separated (i.e. see\nhttps://github.com/pachadotdev/canadamaps/blob/main/data_processing/02_census_divisions_and_derivatives.R).\n\n### Federal Electoral Districts\n\nThese cannot be obtained as sums of CDs, therefore these are stored in their\nown table `federal_electoral_districts`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachadotdev%2Fcanadamaps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpachadotdev%2Fcanadamaps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpachadotdev%2Fcanadamaps/lists"}