2025-03-30

Background

With current events in mind as of March 2025, there is a political climate that revolves around many issues concerning prioritizing American citizens’ self-interests. This policy is spearheaded by the returning president Donald Trump. One of the issues concerning these policies is the issue of immigration, mainly Mexican immigration pouring in from the Southern border. With the focus on how many Mexican immigrants, along with a larger focus on overall foreign-born immigrants, I came across the question of “well what about Mexico itself, how is their immigration status and numbers? What are the major immigrant groups’ nations?” The goal will be to analyze immigration trends in Mexico and go further in depth over any interesting finds.

Data

The data was pulled from the Instituto Nacional de Estadística y Geografía of Mexico. It is data that has been separated by regions, gender, selected countries of origin, and 3 select years: 2000, 2010, 2020.

Note: Some Countries’ names were kept in the original Spanish langauge. The following are the translations: “Estados Unidos Mexicanos” = Mexico (as a whole) , “Estados Unidos de América” = “United States of America” , “Japón” = “Japan” , “España” = “Spain” , “Otros” = Others

More information about the dataset can be found on the following link (although the information will be in Spanish): https://www.inegi.org.mx/app/tabulados/interactivos/?pxq=Migracion_Migracion_03_793b2477-4037-43d4-9a60-90fb2592cdbc&idrt=130&opc=t

## Warning: package 'ggplot2' was built under R version 4.4.3
## Warning: package 'readr' was built under R version 4.4.3
## Warning: package 'dplyr' was built under R version 4.4.3
## Warning: package 'lubridate' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Warning: package 'plotly' was built under R version 4.4.3
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout

Data Setup

data <- read_csv(
  "C:/Users/josem/Downloads/Migracion_03(Tabulado).csv",
  skip = 1,
  col_names = c(
    "Entidad_federativa", "Paises",
    "Total_2000", "Hombres_2000", "Mujeres_2000",
    "Total_2010", "Hombres_2010", "Mujeres_2010",
    "Total_2020", "Hombres_2020", "Mujeres_2020"
  ),
  locale = locale(
    encoding = "Latin1", # deals with accent marks in dataset
    grouping_mark = ","  # Fixes comma-as-thousand-separator
  )
)
## Rows: 232 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): Entidad_federativa, Paises, Total_2000, Hombres_2000, Mujeres_2000...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

North America Plot 2020

# Filter data for specific countries
country_data <- data %>%
    filter(Paises %in% c("Guatemala", "Estados Unidos de América")) %>%
    select(Entidad_federativa, Paises, Total_2020) %>%
    pivot_longer(
        cols = starts_with("Total"),
        names_to = "Year",
        values_to = "Migration",
        names_prefix = "Total_"
    ) %>%
    mutate(Year = as.numeric(Year))

North America Plot 2020

# 3D bar plot
plot_ly(
    country_data,
    x = ~Entidad_federativa,  
    y = ~Paises,              
    z = ~Migration,           
    type = "mesh3d",
    intensity = ~Migration,
    colors = viridis::viridis(100)
) %>%
    layout(
        title = "Migration by State, Country in 2020",
        scene = list(
            xaxis = list(title = "State"),
            yaxis = list(title = "Country"),
            zaxis = list(title = "Migration")
        )
    )

North American Plot 2020

European Plot 2020

country_data <- data %>%
    filter(Paises %in% c("España", "Francia")) %>%
    select(Entidad_federativa, Paises,Total_2020) %>%
    pivot_longer(
        cols = starts_with("Total"),
        names_to = "Year",
        values_to = "Migration",
        names_prefix = "Total_"
    ) %>%
    mutate(Year = as.numeric(Year))

European Plot

# 3D bar plot
plot_ly(
    country_data,
    x = ~Entidad_federativa,  
    y = ~Paises,              
    z = ~Migration,           
    type = "mesh3d",
    intensity = ~Migration,
    colors = viridis::viridis(100)
) %>%
    layout(
        title = "Migration by State, Country in 2020",
        scene = list(
            xaxis = list(title = "State"),
            yaxis = list(title = "Country"),
            zaxis = list(title = "Migration")
        )
    )

European Plot 2020

Others Plot 2020

country_data <- data %>%
    filter(Paises %in% c("Japón", "Otros")) %>%
    select(Entidad_federativa, Paises, Total_2020) %>%
    pivot_longer(
        cols = starts_with("Total"),
        names_to = "Year",
        values_to = "Migration",
        names_prefix = "Total_"
    ) %>%
    mutate(Year = as.numeric(Year))

Others Plot 2020

# Create 3D bar plot
plot_ly(
    country_data,
    x = ~Entidad_federativa,  
    y = ~Paises,              
    z = ~Migration,           
    type = "mesh3d",
    intensity = ~Migration,
    colors = viridis::viridis(100)
) %>%
    layout(
        title = "Migration by State, Country in 2020",
        scene = list(
            xaxis = list(title = "State"),
            yaxis = list(title = "Country"),
            zaxis = list(title = "Migration")
        )
    )

Others Plot 2020

Migrations Trends

Migrations Trends

Migrations Trends

US Migration

us = data %>%
  filter(Paises == "Estados Unidos de América") %>%
  pivot_longer(
    cols = starts_with("Total"),
    names_to = "Year",
    values_to = "Migration",
    names_prefix = "Total_"
  )
ggplot(us, aes(x = Year, y = Migration, group = Entidad_federativa)) +
  geom_line(color = "gray50") +
  geom_point(size = 1) +
  facet_wrap(~Entidad_federativa, scales = "free_y") +
  labs(title = "US Migration by State (2000–2020)") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

US Migration

Gender Distributions (US Immigrants)

Japanese Migration

Japan = data %>%
  filter(Paises == "Japón") %>%
  pivot_longer(
    cols = starts_with("Total"),
    names_to = "Year",
    values_to = "Migration",
    names_prefix = "Total_"
  )
ggplot(Japan, aes(x = Year, y = Migration, group = Entidad_federativa)) +
  geom_line(color = "gray") +
  geom_point(size = 1) +
  facet_wrap(~Entidad_federativa, scales = "free_y") +
  labs(title = "Japanese Migration by State (2000–2020)") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Japanese Migration

Gender Distributions (Japanese Immigrants)