dblogr/

Migration Demographics In Canada

Graphs of migration demographics in Canada using STATCAN data


Data

STATCAN Table: 17-10-0009-01 - Population

STATCAN Table: 17-10-0008-01 - Demographic growth - Annually

STATCAN Table: 17-10-0040-01 - Demographic growth - Quarterly

STATCAN Table: 17-10-0015-01 - Interprovincial migration

STATCAN Table: 17-10-0121-01 - Non-permanent residents

STATCAN Table: 98-10-0361-01 - Non-permanent resident type by place of birth

STATCAN Table: 17-10-0154-01 - Interprovincial and intraprovincial migrants

GOV of CAN: Open Government - Monthly IRCC Updates - Source Countries - New Applications and Extensions Approved for Temporary Residents by Month


Prepare Data

# devtools::install_github("derekmichaelwright/agData")
library(agData)
library(gganimate)
library(readxl)
# Prep data
myCaption <- "derekmichaelwright.github.io/dblogr/blog/canada_migration | Data: STATCAN"
myMeasures <- c("Births", "Deaths", "Net emigration", "Immigrants", 
                "Net non-permanent residents", "Net interprovincial migration")
myColors <- c("darkgreen", "black", "darkred", "steelblue", "darkblue", "darkorange")
myAreas <- c("Canada", "British Columbia", "Alberta", "Saskatchewan", "Manitoba",
             "Ontario", "Quebec", "New Brunswick", "Nova Scotia",
             "Prince Edward Island", "Newfoundland and Labrador",
             "Yukon", "NWT & Nunavut", "Northwest Territories", "Nunavut")
myAges1 <- c("0 to 4 years", "5 to 9 years", 
             "10 to 14 years", "15 to 19 years",
             "20 to 24 years", "25 to 29 years", 
             "30 to 34 years", "35 to 39 years",
             "40 to 44 years", "45 to 49 years", 
             "50 to 54 years", "55 to 59 years",
             "60 to 64 years", "65 to 69 years", 
             "70 to 74 years", "75 to 79 years",
             "80 to 84 years", "85 to 89 years", 
             "90 to 94 years", "95 to 99 years",
             "100 years and over", "All ages")
myAges2 <- c("Total - Age", "0 to 14 years", "15 to 24 years",
             "25 to 64 years", "65 years and over")
myDates <- c("1975/1976","1980/1981","1985/1986","1990/1991","1995/1996",
             "2000/2001","2005/2006","2010/2011","2015/2016", "2020/2021")
#
mySexes1 <- c("Total - gender", "Men+", "Women+")
mySexes2 <- c("Both sexes", "Males", "Females")
#
d1 <- read.csv("1710000901_databaseLoadingData.csv") %>%
  select(Year=REF_DATE, Area=GEO, Unit=UOM, Value=VALUE) %>%
  mutate(Area = gsub("Northwest Territories including", "NWT &", Area),
         Area = factor(Area, levels = myAreas),
         Month = substr(Year, 6, 8),
         Year = substr(Year, 1,4),
         Year = as.numeric(Year),
         Month = as.numeric(Month),
         Date = as.Date(paste(Year, Month, "01", sep = "-")))
pp <- d1 %>% group_by(Area, Year) %>%
  summarise(Population = mean(Value, na.rm = T))
#
d2 <- read.csv("1710000801_databaseLoadingData.csv") %>%
  select(Date=REF_DATE, Area=GEO, Measurement=Components.of.population.growth, 
         Unit=UOM, Value=VALUE) %>%
  mutate(Area = gsub("Northwest Territories including", "NWT &", Area),
         Area = factor(Area, levels = myAreas),
         Measurement = factor(Measurement, levels = myMeasures),
         Year = as.numeric(substr(Date, 1,4)),
         Date = factor(Date))
#
d3 <- read.csv("1710004001_databaseLoadingData.csv") %>%
  select(Date=REF_DATE, Area=GEO, Measurement=Components.of.population.growth, 
         Unit=UOM, Value=VALUE) %>%
  mutate(Area = gsub("Northwest Territories including", "NWT &", Area),
         Area = factor(Area, levels = myAreas),
         Measurement = factor(Measurement, levels = myMeasures),
         Year = as.numeric(substr(Date, 1,4)),
         Date = factor(Date))
#
d4 <- read.csv("1710001501_databaseLoadingData.csv") %>%
  select(Year=REF_DATE, Area=GEO, Sex=Gender, Age=Age.group, 
         Measurement=Migrants, UOM, Value=VALUE) %>%
  mutate(Area = gsub("Northwest Territories including", "NWT &", Area),
         Area = factor(Area, levels = myAreas),
         Age = factor(Age, levels = myAges1),
         Net = ifelse(Value > 0, "Positive", "Negative"),
         Sex = plyr::mapvalues(Sex, mySexes1, mySexes2))
#
d5 <- read.csv("1710012101_databaseLoadingData.csv") %>%
  select(Date=REF_DATE, Area=GEO, Type=Non.permanent.resident.types,
         UOM, Value=VALUE) %>%
  mutate(Area = gsub("Northwest Territories including", "NWT &", Area),
         Area = factor(Area, levels = myAreas),
         Date = factor(Date))
#
d6 <- read.csv("9810036101_databaseLoadingData.csv") %>%
  select(Year=REF_DATE, Area=GEO, Sex=Gender..3., Age=Age..15C., 
         Type=Non.permanent.resident.type..10.,
         POB=Place.of.birth..290., UOM, Value=VALUE) %>%
  mutate(Area = gsub("Northwest Territories including", "NWT &", Area),
         Age = factor(Age, levels = myAges2),
         Sex = plyr::mapvalues(Sex, mySexes1, mySexes2))
# 
d7 <- read.csv("1710015401_databaseLoadingData.csv")
#
myMonths <- c("January", "February", "March", "April", "May", "June",
              "July", "August", "September", "October", "November", "December")
d8 <- read_xlsx("Open Data - OPS TR Approved en.xlsx", range = "A7:AW223")
colnames(d8) <- substr(colnames(d8), 1, regexpr("\\.\\.\\.", colnames(d8))-1)
colnames(d8) <- c("Area", paste(colnames(d8)[2:ncol(d8)], rep(2022:2025, each = 13)))
d8 <- d8 %>%
  gather(Month, Value, 2:ncol(.)) %>%
  separate(Month, c("Month","Year"), sep = " ") %>%
  mutate(Value = as.numeric(Value))
d9 <- d8 %>% filter(Month != "Total") %>%
  mutate(MonthNum = plyr::mapvalues(Month, myMonths, str_pad(1:12, width = 2, pad = "0")),
         Date = as.Date(paste(Year, MonthNum,"01", sep ="-"), format = "%Y-%m-%d"))
d8 <- d8 %>% filter(Month == "Total") %>% select(-Month)

Births, Deaths & Migration

Canada

# Prep data
xx <- d2 %>% 
  filter(Area == "Canada", Measurement %in% myMeasures[1:5]) %>%
  mutate(Measurement = factor(Measurement, levels = myMeasures))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000, color = Measurement)) +
  geom_hline(yintercept = 0, lty = 2, alpha = 0.5) +
  geom_line(size = 1.25, alpha = 0.7) +
  scale_color_manual(name = NULL, values = myColors) +
  theme_agData(legend.position = "bottom") +
  labs(title = "Canada - Population Dynamics", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_01.png", mp, width = 7, height = 4)

Provinces

# Prep data
xx <- d2 %>% filter(Measurement %in% myMeasures)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_hline(yintercept = 0, lty = 2, alpha = 0.5) +
  geom_line(aes(color = Measurement, group = Measurement), 
            size = 1, alpha = 0.7) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_color_manual(name = NULL, values = myColors) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  guides(color = guide_legend(nrow = 1)) +
  labs(title = "Population Dynamics", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_02.png", mp, width = 14, height = 7)

Immigrants vs Emigrants

Canada

# Prep data
xx <- d2 %>% 
  filter(Area == "Canada", Measurement %in% c("Immigrants", "Net emigration")) %>%
  mutate(Value = ifelse(Measurement == "Net emigration", -Value, Value))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Measurement)) +
  geom_hline(yintercept = 0) +
  geom_col(alpha = 0.7, color = "black", lwd = 0.3) +
  scale_fill_manual(name = NULL, values = myColors[3:4]) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Net Migration", x = NULL, 
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_03.png", mp, width = 6, height = 4)

Provinces

All Data

# Prep data
xx <- d2 %>% 
  filter(Measurement %in% c("Immigrants", "Net emigration")) %>%
  mutate(Value = ifelse(Measurement == "Net emigration", -Value, Value))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Measurement)) +
  geom_hline(yintercept = 0) +
  geom_col(alpha = 0.7, color = "black", lwd = 0.1) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_fill_manual(name = NULL, values = myColors[3:4]) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Net Migration", x = NULL, 
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_04.png", mp, width = 14, height = 7)

Net Migration

# Prep data
xx <- d2 %>% 
  filter(Measurement %in% c("Immigrants", "Net emigration")) %>%
  spread(Measurement, Value) %>%
  mutate(Net = Immigrants - `Net emigration`,
         Group = ifelse(Net > 0, "Positive", "Negative"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Net / 1000, fill = Group)) +
  geom_hline(yintercept = 0) +
  geom_col(alpha = 0.7, color = "black", lwd = 0.1) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_fill_manual(name = NULL, values = myColors[3:4]) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "none",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Net Migration", x = NULL, 
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_05.png", mp, width = 14, height = 7)

Prairies vs. Non-Prairies

# Prep data
myC <- c("steelblue", "red", "darkorange", 
          "darkblue", "darkgreen", "darkred")
myA <- c("Quebec", "Ontario", "British Columbia", 
          "Alberta", "Saskatchewan", "Manitoba")
myW <- c("Non-Prairies", "Non-Prairies", "Non-Prairies", 
          "Prairies", "Prairies", "Prairies")
x1 <- d1 %>% 
  filter(Month == 1) %>%
  select(Area, Year, Population=Value)
x2 <- d2 %>% 
  filter(Measurement == "Immigrants") %>%
  select(Area, Year, Immigrants=Value)
xx <- left_join(x1, x2, by = c("Area", "Year")) %>%
  filter(Area %in% myA, !is.na(Immigrants)) %>%
  mutate(Value = 1000000 * Immigrants / Population,
         Area = factor(Area, levels = myA),
         Wing = plyr::mapvalues(Area, myA, myW))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value, color = Area)) +
  geom_line(alpha = 0.2) + 
  geom_smooth(se = F) +
  facet_grid(. ~ Wing) +
  scale_x_continuous(breaks = seq(1975, 2015, 10)) +
  scale_color_manual(name = NULL, values = myC) +
  theme_agData() +
  labs(title = "Immigration Rates", x = NULL,
       y = "Immigrants / Million People", caption = myCaption)
ggsave("canada_migration_1_06.png", mp, width = 8, height = 4)

Immigrants & Non-Permanent Residents

Canada

# Prep data
xx <- d2 %>% 
  filter(Area == "Canada", 
         Measurement %in% c("Immigrants", "Net non-permanent residents"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Measurement)) +
  geom_hline(yintercept = 0, line.width = 0.5) +
  geom_col(color = "black", alpha = 0.7, lwd = 0.3) +
  scale_fill_manual(name = NULL, values = myColors[4:5]) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Immigrants & Non-Permanent Residents", 
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_1_07.png", mp, width = 6, height = 4)

Provinces

# Prep data
xx <- d2 %>% 
  filter(Measurement %in% c("Immigrants", "Net non-permanent residents"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Measurement)) +
  geom_hline(yintercept = 0, line.width = 0.5) +
  geom_col(color = "black", alpha = 0.7, lwd = 0.3) +
  facet_wrap(Area ~ ., scales = "free_y", ncol = 5) +
  scale_fill_manual(name = NULL, values = myColors[4:5]) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Immigrants & Non-Permanent Residents",
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_1_08.png", mp, width = 14, height = 7)

Components of Growth

By Year

# Prep data
x1 <- d2 %>% filter(Area == "Canada", Measurement %in% myMeasures[1:2]) %>%
  spread(Measurement, Value) %>%
  mutate(`Naturalized Growth` = Births - Deaths) %>%
  gather(Measurement, Value, `Naturalized Growth`)
x2 <- d2 %>% filter(Area == "Canada", Measurement %in% myMeasures[3:4]) %>%
  spread(Measurement, Value) %>%
  mutate(`Net Immigration` = Immigrants - `Net emigration`) %>%
  gather(Measurement, Value, `Net Immigration`)
x3 <- d2 %>% filter(Area == "Canada", Measurement %in% myMeasures[5])
#
myLevels <- c("Net non-permanent residents","Net Immigration","Naturalized Growth")
xx <- bind_rows(x1, x2, x3) %>%
  mutate(Measurement = factor(Measurement, levels = myLevels))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 100000, fill = Measurement)) +
  geom_col(color = "black", alpha = 0.7) +
  scale_fill_manual(name = NULL, values = myColors[c(5:4,1)]) +
  theme_agData(legend.position = "bottom") +
  labs(title = "Components of Population Growth in Canada",
       y = "x100,000", x = NULL, caption = myCaption)
ggsave("canada_migration_1_09.png", mp, width = 7, height = 4)

Since 2015

# Prep data
x1 <- d2 %>% filter(Area == "Canada", Measurement %in% myMeasures[1:2]) %>%
  spread(Measurement, Value) %>%
  mutate(`Naturalized Growth` = Births - Deaths) %>%
  gather(Measurement, Value, `Naturalized Growth`)
x2 <- d2 %>% filter(Area == "Canada", Measurement %in% myMeasures[3:4]) %>%
  spread(Measurement, Value) %>%
  mutate(`Net Immigration` = Immigrants - `Net emigration`) %>%
  gather(Measurement, Value, `Net Immigration`)
x3 <- d2 %>% filter(Area == "Canada", Measurement %in% myMeasures[5])
#
myLevels <- c("Net non-permanent residents","Net Immigration","Naturalized Growth")
xx <- bind_rows(x1, x2, x3) %>%
  mutate(Measurement = factor(Measurement, levels = myLevels)) %>%
  filter(Year > 2015) %>%
  group_by(Measurement) %>%
  summarise(Value = sum(Value))
# Plot
mp <- ggplot(xx, aes(x = Measurement, y = Value / 1000000, fill = Measurement)) +
  geom_col(color = "black", alpha = 0.7) +
  scale_fill_manual(name = NULL, values = myColors[c(5:4,1)]) +
  theme_agData(legend.position = "bottom") +
  labs(title = "Components of Population Growth in Canada since 2015",
       y = "Million People", x = NULL, caption = myCaption)
ggsave("canada_migration_1_10.png", mp, width = 6, height = 4)

Net Interprovincial Migration

Canada

# Prep data
xx <- d2 %>% 
  filter(Measurement == "Net interprovincial migration") %>%
  mutate(Group = ifelse(Value > 0, "Positive", "Negative"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Group)) +
  geom_hline(yintercept = 0) +
  geom_col(alpha = 0.7, color = "black", lwd = 0.2) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_fill_manual(name = NULL, values = myColors[3:4]) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "none",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Net Interprovincial Migration", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_11.png", mp, width = 14, height = 7)

Alberta vs BC

# Prep data
xx <- d2 %>% 
  filter(Area %in% c("Alberta", "British Columbia"),
         Measurement == "Net interprovincial migration")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Area, group = Area)) +
  geom_hline(yintercept = 0) +
  geom_line(alpha = 0.7, size = 1.5) +
  scale_color_manual(name = NULL, values = c("darkorange","darkblue")) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Net Interprovincial Migration", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_1_12.png", mp, width = 6, height = 4)

1946 <

Quarterly

# Prep data
xx <- d3 %>% 
  filter(Area == "Canada", Measurement %in% myMeasures[1:5]) %>%
  mutate(Measurement = factor(Measurement, levels = myMeasures))
myLabels <- paste0(seq(1950,2025,5),"-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_hline(yintercept = 0, lty = 2, alpha = 0.5) +
  geom_line(aes(color = Measurement, group = Measurement), 
            size = 1.25, alpha = 0.7) +
  geom_line(y = 0,  alpha = 0.7, color = "black") +
  scale_color_manual(name = NULL, values = myColors[3:5]) +
  scale_x_discrete(breaks = myLabels) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Population Dynamics", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_2_01.png", mp, width = 6, height = 4)

Immigrants

# Prep data
xx <- d3 %>% 
  filter(Area == "Canada", Measurement == "Immigrants")
myLabels <- paste0(seq(1950,2025,5),"-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_hline(yintercept = 0, lty = 2, alpha = 0.5) +
  geom_line(aes(color = Measurement, group = Measurement), 
            size = 1.25, alpha = 0.7) +
  geom_line(y = 0,  alpha = 0.7, color = "black") +
  scale_color_manual(name = NULL, values = "black") +
  scale_x_discrete(breaks = myLabels) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Population Dynamics", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_2_02.png", mp, width = 6, height = 4)

Non permenant residents

# Prep data
xx <- d3 %>% 
  filter(Area == "Canada", Measurement == "Net non-permanent residents") %>%
  mutate(Measurement = factor(Measurement, levels = myMeasures))
myLabels <- paste0(seq(1950,2025,5),"-01")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_hline(yintercept = 0, lty = 2, alpha = 0.5) +
  geom_line(aes(color = Measurement, group = Measurement), 
            size = 1.25, alpha = 0.7) +
  geom_line(y = 0,  alpha = 0.7, color = "black") +
  scale_color_manual(name = NULL, values = "darkred") +
  scale_x_discrete(breaks = myLabels) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Population Dynamics", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_2_03.png", mp, width = 6, height = 4)

Interprovincial Migration By Age

Plotting Function

# Create plotting function
ggInterProv <- function(myArea) {
  #Prep data
  xx <- d4 %>% 
    filter(Area == myArea, !Year %in% c("1971/1972","1972/1973"),
           Sex == "Both sexes", Age != "All ages",
           Measurement == "Net-migration")
  # Plot
  ggplot(xx, aes(x = Age, y = Value / 1000, fill = Net)) +
    geom_col(color = "black", alpha = 0.7) +
    facet_wrap(. ~ Year, ncol = 10) +
    scale_fill_manual(values = c("darkred", "steelblue")) +
    theme_agData(legend.position = "none",
                 axis.text.x = element_text(angle = 45, hjust = 1, size = 5)) +
    labs(title = paste(myArea, "- Net Interprovincial Migration"), x = NULL,
         y = "Thousand People", caption = myCaption)
}

British Columbia

# Plot
mp <- ggInterProv(myArea = "British Columbia")
ggsave("canada_migration_3_01.png", mp, width = 20, height = 10)

Alberta

# Plot
mp <- ggInterProv(myArea = "Alberta")
ggsave("canada_migration_3_02.png", mp, width = 20, height = 10)

Saskatchewan

# Plot
mp <- ggInterProv(myArea = "Saskatchewan")
ggsave("canada_migration_3_03.png", mp, width = 20, height = 10)

Manitoba

# Plot
mp <- ggInterProv(myArea = "Manitoba")
ggsave("canada_migration_3_04.png", mp, width = 20, height = 10)

Ontario

# Plot
mp <- ggInterProv(myArea = "Ontario")
ggsave("canada_migration_3_04.png", mp, width = 20, height = 10)

Quebec

# Plot
mp <- ggInterProv(myArea = "Quebec")
ggsave("canada_migration_3_05.png", mp, width = 20, height = 10)

Alberta 2012 - 2024

# Prep data
myYears <- paste0(2012:2023,"/",2013:2024)
xx <- d4 %>% 
  filter(Area == "Alberta", Year %in% myYears,
         Sex == "Both sexes", Age != "All ages",
         Measurement == "Net-migration")
# Plot
mp <- ggplot(xx, aes(x = Age, y = Value, fill = Net)) +
  geom_col(color = "black", alpha = 0.7) +
  facet_wrap(. ~ Year, ncol = 6) +
  scale_fill_manual(values = c("darkred", "steelblue")) +
  theme_agData(legend.position = "none",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Alberta Net Interprovincial Migration", 
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_3_06.png", mp, width = 14, height = 6)

British Columbia 2021 - 2024

# Prep data
myYears <- paste0(2021:2023,"/",2022:2024)
xx <- d4 %>% 
  filter(Area == "British Columbia", Year %in% myYears,
         Sex == "Both sexes", Age != "All ages",
         Measurement == "Net-migration")
# Plot
mp <- ggplot(xx, aes(x = Age, y = Value, fill = Net)) +
  geom_col(color = "black", alpha = 0.7) +
  facet_grid(. ~ Year) +
  scale_fill_manual(values = myColors[3:4]) +
  theme_agData(legend.position = "none",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "British Columbia Net Interprovincial Migration", x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_3_07.png", mp, width = 8, height = 4)

Birth Rates

Canada

# Prep data
xx <- d2 %>% filter(Measurement == "Births") %>%
  left_join(pp, by = c("Area","Year")) %>%
  mutate(BirthRate = 1000 * Value / Population)
# Plot
mp <- ggplot(xx %>% filter(Area == "Canada"), aes(Date, y = BirthRate)) +
  geom_col(color = "black", fill = "darkgreen", alpha = 0.7, lwd = 0.3) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  theme_agData() +
  labs(title = "Birth Rates in Canada", x = NULL,
       y = "Births / Thousand People", caption = myCaption)
ggsave("canada_migration_4_01.png", mp, width = 6, height = 4)

Birth Rates

Canada

# Prep data
x1 <- d2 %>% filter(Measurement == "Births") %>%
  select(Year, Date, Area, Births=Value)
x2 <- d1 %>% filter(Month == 1) %>%
  select(Year, Area, Population=Value)
xx <- left_join(x1, x2, by = c("Year", "Area")) %>%
  mutate(BirthRate = Births / Population)
# Plot
mp <- ggplot(xx, aes(x = Date, y = BirthRate * 1000)) + 
  geom_col(color = "black", fill = "darkgreen", alpha = 0.7, lwd = 0.1) + 
  facet_wrap(Area ~ ., ncol = 5) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Birth Rates in Canada", x = NULL,
       y = "Births / Thousand People", caption = myCaption)
ggsave("canada_migration_4_02.png", mp, width = 14, height = 7)

Saskatchewan

# Prep data
xx <- d2 %>% 
  filter(Area == "Saskatchewan", Measurement %in% c("Births","Deaths"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, 
                     color = Measurement, group = Measurement)) + 
  geom_line(line.width = 1.5, alpha = 0.7, size = 1.5) + 
  scale_color_manual(name = NULL, values = myColors) +
  scale_y_continuous(minor_breaks = 0:20, limits = c(0.5,18.5)) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Population Dynamics in Saskatchewan", 
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_4_03.png", mp, width = 6, height = 4)

British Columbia

# Prep data
xx <- d2 %>% 
  filter(Area == "British Columbia", Measurement %in% c("Births","Deaths"))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, 
                     color = Measurement, group = Measurement)) + 
  geom_line(line.width = 1.5, alpha = 0.7, size = 1.5) + 
  scale_color_manual(name = NULL, values = myColors) +
  scale_y_continuous(limits = c(1,48)) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Population Dynamics in British Columbia", 
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_4_04.png", mp, width = 6, height = 4)

Maritimes

# Prep data
xx <- d2 %>% 
  filter(Measurement %in% c("Births","Deaths"),
         Area %in% c("Prince Edward Island", "Nova Scotia", "New Brunswick",
                     "Newfoundland and Labrador")) %>% 
  group_by(Date, Measurement) %>%
  summarise(Value = sum(Value))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, 
                     color = Measurement, group = Measurement)) + 
  geom_line(line.width = 1.5, alpha = 0.7, size = 1.5) + 
  scale_color_manual(name = NULL, values = myColors) +
  scale_y_continuous(limits = c(1,42)) +
  scale_x_discrete(breaks = myDates) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Population Dynamics in The Maritimes", 
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_4_05.png", mp, width = 6, height = 4)

Non-permentant Residents

Canada

# Prep Data
myTypes <- c("Total, asylum claimants, protected persons and related groups",
             "Total, permit holders and their family members")
xx <- d5 %>% 
  filter(Area == "Canada", Type %in% myTypes)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000000, fill = Type)) +
  geom_col(color = "black", alpha = 0.7) +
  scale_fill_manual(name = NULL, values = c("darkred", "steelblue")) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  guides(fill = guide_legend(ncol = 1)) +
  labs(title = "Canada", subtitle = "Total, non-permanent residents", 
       y = "Million People", x = NULL, caption = myCaption)
ggsave("canada_migration_5_01.png", mp, width = 6, height = 5)

Provinces

# Prep Data
myTypes <- c("Total, asylum claimants, protected persons and related groups",
             "Total, permit holders and their family members")
xx <- d5 %>% filter(Type %in% myTypes)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Type)) +
  geom_col(color = "black", alpha = 0.7) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_fill_manual(name = NULL, values = c("darkred", "steelblue")) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada", subtitle = "Total, non-permanent residents", 
       x = NULL, y = "Thousand People", caption = myCaption)
ggsave("canada_migration_5_02.png", mp, width = 14, height = 7)

Permit Holders

Canada

# Prep Data
myTypes <- c("Work permit holders only", "Study permit holders only",
             "Work and study permit holders", "Other")
xx <- d5 %>% 
  filter(Area == "Canada", Type %in% myTypes)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Type)) +
  geom_col(color = "black", alpha = 0.7) +
  scale_fill_manual(name = NULL, values = myColors[c(3,1,2,4)]) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  guides(fill = guide_legend(ncol = 2)) +
  labs(title = "Canada - Temperary residents", 
       subtitle = "Total, permit holders and their family members",
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_5_03.png", mp, width = 6, height = 5)

Provinces

# Prep Data
myTypes <- c("Work permit holders only", "Study permit holders only",
             "Work and study permit holders", "Other")
xx <- d5 %>% 
  filter(Area != "Canada", Type %in% myTypes)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Type)) +
  geom_col(color = "black", alpha = 0.7) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_fill_manual(name = NULL, values = myColors[c(3,1,2,4)]) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Temperary residents", 
       subtitle = "Total, permit holders and their family members",x = NULL,
       y = "Thousand People", caption = myCaption)
ggsave("canada_migration_5_04.png", mp, width = 14, height = 7)

Assylum Seekers

Canada

# Prep Data
myTypes <- c("Asylum claimants, protected persons and related groups with work permit only",
             "Asylum claimants, protected persons and related groups with study permit only",
             "Asylum claimants, protected persons and related groups with work and study permits",
             "Asylum claimants, protected persons and related groups without work or study permits")
xx <- d5 %>% 
  filter(Area == "Canada", Type %in% myTypes) %>%
  mutate(Type = gsub("Asylum claimants, protected persons and related groups ", "", Type))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Type)) +
  geom_col(color = "black", alpha = 0.7) +
  scale_fill_manual(name = NULL, values = myColors[c(1,2,4,3)]) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  guides(fill = guide_legend(ncol = 2)) +
  labs(title = "Canada - Asylum claimants, protected persons and related groups",
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_5_05.png", mp, width = 7, height = 5)

Provinces

# Prep Data
myTypes <- c("Asylum claimants, protected persons and related groups with work permit only",
             "Asylum claimants, protected persons and related groups with study permit only",
             "Asylum claimants, protected persons and related groups with work and study permits",
             "Asylum claimants, protected persons and related groups without work or study permits")
xx <- d5 %>% 
  filter(Area != "Canada", Type %in% myTypes) %>%
  mutate(Type = gsub("Asylum claimants, protected persons and related groups ", "", Type))
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, fill = Type)) +
  geom_col(color = "black", alpha = 0.7) +
  facet_wrap(Area ~ ., ncol = 5, scales = "free_y") +
  scale_fill_manual(name = NULL, values = myColors[c(1,2,4,3)]) +
  theme_agData(legend.position = "bottom",
               axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Canada - Asylum claimants, protected persons and related groups",
       y = "Thousand People", x = NULL, caption = myCaption)
ggsave("canada_migration_5_06.png", mp, width = 14, height = 7)

Origin

2024

# Prep data
xx <- d8 %>% 
  filter(Area != "Total", Year == 2024) %>%
  arrange(desc(Value)) %>%
  slice(1:10) %>%
  mutate(Area = factor(Area, levels = rev(Area)))
# Plot
mp <- ggplot(xx, aes(x = Area, y = Value / 1000)) +
  geom_col(fill = "steelblue", color = "black", alpha = 0.7) +
  theme_agData() +
  coord_flip() +
  labs(title = "2024 Origin of Temperary Residents", x = NULL, 
       y = "Thousand people", caption = myCaption)
ggsave("canada_migration_6_01.png", mp, width = 6, height = 4)

Since 2022

# Prep data
xx <- d8 %>% 
  filter(Area != "Total") %>%
  group_by(Area) %>%
  summarise(Value = sum(Value)) %>%
  ungroup() %>%
  arrange(desc(Value)) %>%
  slice(1:10) %>%
  mutate(Area = factor(Area, levels = rev(Area)))
# Plot
mp <- ggplot(xx, aes(x = Area, y = Value / 1000000)) +
  geom_col(fill = "steelblue", color = "black", alpha = 0.7) +
  theme_agData() +
  coord_flip() +
  labs(title = "Origin of Temperary Residents Since 2022", 
       x = NULL, y = "Million people", caption = myCaption)
ggsave("canada_migration_6_02.png", mp, width = 6, height = 4)

India

# Prep data
xx <- d9 %>% filter(Area == "India") 
# Plot
ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_col(fill = "steelblue", color = "black", alpha = 0.7) +
  theme_agData() +
  labs(title = "Temperary Residents From India", x = NULL, 
       y = "Thousand people", caption = myCaption)

ggsave("canada_migration_6_03.png", mp, width = 6, height = 4)

China

# Prep data
xx <- d9 %>% filter(Area == "People's Republic of China") 
# Plot
ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_col(fill = "steelblue", color = "black", alpha = 0.7) +
  theme_agData() +
  labs(title = "Temperary Residents From China", x = NULL, 
       y = "Thousand people", caption = myCaption)

ggsave("canada_migration_6_04.png", mp, width = 6, height = 4)

Ukraine

# Prep data
xx <- d9 %>% filter(Area == "Ukraine") 
# Plot
ggplot(xx, aes(x = Date, y = Value / 1000)) +
  geom_col(fill = "steelblue", color = "black", alpha = 0.7) +
  theme_agData() +
  labs(title = "Temperary Residents From India", x = NULL, 
       y = "Thousand people", caption = myCaption)

ggsave("canada_migration_6_05.png", mp, width = 6, height = 4)


dblogr/


© Derek Michael Wright