canadamaps

Maps of the Political and Administrative Divisions of Canada.

https://github.com/pachadotdev/canadamaps

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.7%) to scientific vocabulary

Keywords

canada maps
Last synced: 6 months ago · JSON representation

Repository

Maps of the Political and Administrative Divisions of Canada.

Basic Info
Statistics
  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • Open Issues: 1
  • Releases: 0
Topics
canada maps
Created almost 5 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog Funding License Code of conduct Codemeta

README.Rmd

---
output: github_document
---




[![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)

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

# canadamaps

## General idea

The idea is to avoid "duplications", for example instead of adding a provinces 
map or others, we provide functions to sum Census Divisions in all possible 
cases.

```{r general, message=FALSE, warning=FALSE}
library(ggplot2)
library(canadamaps)

ggplot(data = census_divisions) +
  geom_sf(aes(geometry = geometry)) +
  labs(title = "Canada's Census Divisions")
```

The same idea can be applied to other maps with different levels of aggregation.

```{r other_maps, eval=FALSE}
ggplot(data = get_agricultural_divisions()) +
  geom_sf(aes(geometry = geometry)) +
  labs(title = "Canada's Census Agricultural Regions")

ggplot(data = get_economic_regions()) +
  geom_sf(aes(geometry = geometry)) +
  labs(title = "Canada's Economic Regions")

ggplot(data = federal_electoral_districts) +
  geom_sf(aes(geometry = geometry)) +
  labs(title = "Canada's Federal Electoral Districts")

ggplot(data = get_provinces()) +
  geom_sf(aes(geometry = geometry)) +
  labs(title = "Canada's Provinces")
```

## Lambert projection

We 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).

```{r lambert, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}
# shortcut function to change the CRS
census_divisions <- lambert_projection(census_divisions)

ggplot(data = census_divisions) +
  geom_sf(aes(geometry = geometry)) +
  labs(title = "Canada's Census Divisions")
```

## Using real data

Let'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.

```{r covid_map, warning=FALSE, message=FALSE}
library(readr)
library(dplyr)
library(sf)

url <- "https://health-infobase.canada.ca/src/data/covidLive/vaccination-coverage-map.csv"
csv <- paste0("data_processing/", gsub(".*/", "", url))
if (!file.exists(csv)) download.file(url, csv)

vaccination <- read_csv(csv, col_types = cols(prop5plus_atleast1dose = col_character())) %>%
  filter(week_end == as.Date("2024-02-25"), pruid != 1) %>%
  select(pruid, proptotal_atleast1dose) %>%
  mutate(
    proptotal_atleast1dose = as.numeric(case_when(
      proptotal_atleast1dose == ">=99" ~ 99,
      TRUE ~ proptotal_atleast1dose
    ))
  )

vaccination <- vaccination %>%
  inner_join(get_provinces(), by = "pruid") %>% # canadamaps in action
  mutate(
    label = paste(gsub(" /.*", "", prname),
      paste0(proptotal_atleast1dose, "%"),
      sep = "\n"
    ),
  )
```

An initial plot can be done with the following code.

```{r covid_map_2, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}
# colours obtained with Chromium's inspector
colours <- c("#efefa2", "#c2e699", "#78c679", "#31a354", "#006837")

ggplot(vaccination) +
  geom_sf(aes(fill = proptotal_atleast1dose, geometry = geometry)) +
  geom_sf_label(aes(label = label, geometry = geometry)) +
  scale_fill_gradientn(colours = colours, name = "Cumulative percent") +
  labs(title = "Cumulative percent of the population who have received at least 1 dose of a COVID-19 vaccine") +
  theme_minimal(base_size = 13)
```

We can use different ggplot themes.

```{r covid_map_3, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}
ggplot(vaccination) +
  geom_sf(aes(fill = proptotal_atleast1dose, geometry = geometry)) +
  geom_sf_label(aes(label = label, geometry = geometry)) +
  scale_fill_gradientn(colours = colours, name = "Cumulative percent") +
  labs(title = "Cumulative percent of the population who have received at least 1 dose of a COVID-19 vaccine") +
  theme_void() +
  theme(
    legend.position = "top",
    plot.title = element_text(hjust = 0.5)
  )
```

If we want to fill the information for Alberta, which is not seen in the original map, we can fill and then filter.

```{r covid_map_4, warning=FALSE, message=FALSE, fig.width=10, fig.height=6}
library(tidyr)

vaccination <- read_csv(csv, col_types = cols(prop5plus_atleast1dose = col_character())) %>%
  arrange(pruid, week_end) %>%
  group_by(pruid) %>%
  fill(proptotal_atleast1dose, .direction = "down") %>% # Alberta is filled with an older value
  filter(week_end == as.Date("2024-02-25"), pruid != 1) %>%
  select(pruid, proptotal_atleast1dose) %>%
  mutate(
    proptotal_atleast1dose = as.numeric(case_when(
      proptotal_atleast1dose == ">=99" ~ 99,
      TRUE ~ proptotal_atleast1dose
    ))
  ) %>%
  inner_join(get_provinces(), by = "pruid") %>% # canadamaps in action
  mutate(
    label = paste(gsub(" /.*", "", prname),
      paste0(proptotal_atleast1dose, "%"),
      sep = "\n"
    ),
  ) %>%
  lambert_projection()

ggplot(vaccination) +
  geom_sf(aes(fill = proptotal_atleast1dose, geometry = geometry)) +
  geom_sf_label(aes(label = label, geometry = geometry)) +
  scale_fill_gradientn(colours = colours, name = "Cumulative percent") +
  labs(title = "Cumulative percent of the population who have received at least 1 dose of a COVID-19 vaccine") +
  theme_minimal(base_size = 13)
```

## Units of aggregation

### Census Division

The finest division in this package is the Census Division (CDs) which can be
of the next types (reference: https://www.statcan.gc.ca/en/subjects/standard/sgc/2011/sgc-tab-d).

|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         |
|------------------------|----------------------------------------------|---------------------------------------|---------------------------------------------|--------------------------------------|---------------------------------------|-----------------------------------------|
|Bilingual               |CDR                                           |Census division                        |CDR                                          |Division de recensement               |CDR                                    |Census division / Division de recensement|
|Bilingual               |CT                                            |County                                 |CT                                           |Comté                                 |CT                                     |County / Comté                           |
|English only            |CTY                                           |County                                 |CTY                                          |County                                |CTY                                    |County                                   |
|English only            |DIS                                           |District                               |DIS                                          |District                              |DIS                                    |District                                 |
|English only            |DM                                            |District municipality                  |DM                                           |District municipality                 |DM                                     |District municipality                    |
|French only             |MRC                                           |Municipalité régionale de comté        |MRC                                          |Municipalité régionale de comté       |MRC                                    |Municipalité régionale de comté          |
|English only            |RD                                            |Regional district                      |RD                                           |Regional district                     |RD                                     |Regional district                        |
|English only            |REG                                           |Region                                 |REG                                          |Region                                |REG                                    |Region                                   |
|English only            |RM                                            |Regional municipality                  |RM                                           |Regional municipality                 |RM                                     |Regional municipality                    |
|French only             |TÉ                                            |Territoire équivalent                  |TÉ                                           |Territoire équivalent                 |TÉ                                     |Territoire équivalent                    |
|Bilingual               |TER                                           |Territory                              |TER                                          |Territoire                            |TER                                    |Territory / Territoire                   |
|English only            |UC                                            |United counties                        |UC                                           |United counties                       |UC                                     |United counties                          |

The division type is specified in the `census_divisions` table.

### Census Agricultural Regions

Census Agricultural Regions (CARs) can be obtained as sums of CDs. Excluding
some special cases for Northwestern Territories, Nunavur and Yukon that we
clarified over email communication, the source to match CDs to CARs was obtained
from [Census of Agriculture Reference Maps](https://www150.statcan.gc.ca/n1/pub/95-630-x/95-630-x2017000-eng.htm)
and manually organized in a spreadsheet (https://github.com/pachadotdev/canadamaps/tree/main/data_xlsx).

### Economic Regions

Economic Regions (ERs) can be obtained as sums of CDs. The only special case is
the Halton, which belongs to two economic zones and it's the only CD that has
to be carefully separated (i.e. see
https://github.com/pachadotdev/canadamaps/blob/main/data_processing/02_census_divisions_and_derivatives.R).

### Federal Electoral Districts

These cannot be obtained as sums of CDs, therefore these are stored in their
own table `federal_electoral_districts`.

Owner

  • Name: Mauricio "Pachá" Vargas Sepúlveda
  • Login: pachadotdev
  • Kind: user

Statistician interested in applying statistical methods to address specific policy-relevant questions, particularly in international trade.

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "canadamaps",
  "description": "Terrestrial maps with simplified topologies for Census Divisions, Agricultural Regions, Economic Regions, Federal Electoral Divisions and Provinces.",
  "name": "canadamaps: Maps of the Political and Administrative Divisions of Canada",
  "codeRepository": "https://github.com/pachadotdev/canadamaps/",
  "issueTracker": "https://github.com/pachadotdev/canadamaps/issues",
  "license": "Apache License 2",
  "version": "0.2.1",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.3.1 (2023-06-16)",
  "provider": {
    "@id": "https://cran.r-project.org",
    "@type": "Organization",
    "name": "Comprehensive R Archive Network (CRAN)",
    "url": "https://cran.r-project.org"
  },
  "author": [
    {
      "@type": "Person",
      "givenName": "Mauricio",
      "familyName": "Vargas Sepulveda",
      "email": "mv.sepulveda@mail.utoronto.ca"
    }
  ],
  "contributor": [
    {
      "@type": "Organization",
      "name": "Statistics Canada"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Mauricio",
      "familyName": "Vargas Sepulveda",
      "email": "mv.sepulveda@mail.utoronto.ca"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "ggplot2",
      "name": "ggplot2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ggplot2"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 3.5.0"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "sf",
      "name": "sf",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=sf"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "rmapshaper",
      "name": "rmapshaper",
      "version": "== 0.4.6",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmapshaper"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "dplyr",
      "name": "dplyr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=dplyr"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "magrittr",
      "name": "magrittr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=magrittr"
    },
    "6": {
      "@type": "SoftwareApplication",
      "identifier": "rlang",
      "name": "rlang",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rlang"
    },
    "SystemRequirements": null
  },
  "fileSize": "4407.985KB",
  "releaseNotes": "https://github.com/pachadotdev/canadamaps/blob/master/NEWS.md",
  "readme": "https://github.com/pachadotdev/canadamaps/blob/main/README.md",
  "contIntegration": "https://github.com/pachadotdev/canadamaps/actions",
  "keywords": [
    "maps",
    "canada"
  ]
}

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 28
  • Total Committers: 2
  • Avg Commits per committer: 14.0
  • Development Distribution Score (DDS): 0.357
Past Year
  • Commits: 9
  • Committers: 1
  • Avg Commits per committer: 9.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mauricio Vargas m****1@u****l 18
Mauricio Vargas m****s@d****l 10
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 2.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 2.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • a-laborie (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 292 last-month
  • Total docker downloads: 55
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: canadamaps

Maps of the Political and Administrative Divisions of Canada

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 292 Last month
  • Docker Downloads: 55
Rankings
Forks count: 28.8%
Dependent packages count: 29.8%
Stargazers count: 35.2%
Dependent repos count: 35.5%
Average: 38.5%
Downloads: 63.4%
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.5.0 depends
  • sf * depends
  • dplyr * imports
  • magrittr * imports
  • rlang * imports
  • rmapshaper * imports
  • ggplot2 * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat * suggests