TX Latinas

Responding to a request for Data on Latina women in Texas overall pop over time and hisp origin

library(tidycensus)
Warning: package 'tidycensus' was built under R version 4.2.3
library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.2.3
library(dplyr)
Warning: package 'dplyr' was built under R version 4.2.3

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(scales)
Warning: package 'scales' was built under R version 4.2.3
library(sf)
Warning: package 'sf' was built under R version 4.2.3
Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(tigris)
Warning: package 'tigris' was built under R version 4.2.3
To enable caching of data, set `options(tigris_use_cache = TRUE)`
in your R script or .Rprofile.
library(stringr)
Warning: package 'stringr' was built under R version 4.2.3

Latino Men in Texas Over Time

# # Function to get population data for Hispanic/Latina women in Texas from ACS using 5-year estimates
# get_hispanic_population_acs_5yr <- function(year) {
#   pop_data <- get_acs(
#     geography = "state",
#     variables = "B01001I_002E", # This is the variable for Hispanic/Latina women
#     state = "TX",
#     year = year,
#     survey = "acs5"
#   )
#   pop_data <- rename(pop_data, Hispanic_Latina_Women = estimate)
#   pop_data$Year <- year
#   return(pop_data)
# }
# 
# # Get population data for 2009, 2010, 2011, ..., 2020, 2021, and 2022 using 5-year estimates
# years_5yr <- seq(2009, 2022, by = 1)  # Adjusted to fetch data for all years
# hispanic_population_acs_5yr <- bind_rows(lapply(years_5yr, get_hispanic_population_acs_5yr))
# 
# # Plot population growth
# ggplot(hispanic_population_acs_5yr, aes(x = Year, y = Hispanic_Latina_Women)) +
#   geom_line(color = "blue") +
#   geom_point(color = "blue") +
#   scale_y_continuous(labels = scales::comma) +
#   labs(
#     title = "Population of Hispanic/Latina Women in Texas (2009-2022)",
#     x = "Year",
#     y = "Population",
#     caption = "Data Source: U.S. Census Bureau, American Community Survey 5-Year Estimates"
#   ) +
#   theme_minimal()
# 
# # Create a data frame with the results
# results_table <- data.frame(
#   Year = hispanic_population_acs_5yr$Year,
#   Hispanic_Latina_Women = hispanic_population_acs_5yr$Hispanic_Latina_Women
# )
# 
# # Print the table
# kable(results_table, format = "markdown", caption = "Population of Hispanic/Latina Women in Texas (2009-2022) using 5-year ACS estimates")

Latina Women in Texas Over Time

get_hispanic_population_acs_5yr <- function(year) {
  pop_data <- get_acs(
    geography = "state",
    variables = "B01001I_017E", # Variable for Hispanic/Latina women
    state = "TX",
    year = year,
    survey = "acs5"
  )
  pop_data <- rename(pop_data, Hispanic_Latina_Women = estimate)
  pop_data$Year <- year
  return(pop_data)
}

# Get population data for 2009, 2010, 2011, ..., 2020, 2021, and 2022 using 5-year estimates
years_5yr <- seq(2009, 2022, by = 1)
hispanic_population_acs_5yr <- bind_rows(lapply(years_5yr, get_hispanic_population_acs_5yr))
Getting data from the 2005-2009 5-year ACS
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.
This warning is displayed once per session.
Getting data from the 2006-2010 5-year ACS
Getting data from the 2007-2011 5-year ACS
Getting data from the 2008-2012 5-year ACS
Getting data from the 2009-2013 5-year ACS
Getting data from the 2010-2014 5-year ACS
Getting data from the 2011-2015 5-year ACS
Getting data from the 2012-2016 5-year ACS
Getting data from the 2013-2017 5-year ACS
Getting data from the 2014-2018 5-year ACS
Getting data from the 2015-2019 5-year ACS
Getting data from the 2016-2020 5-year ACS
Getting data from the 2017-2021 5-year ACS
Getting data from the 2018-2022 5-year ACS
# Plot 
ggplot(hispanic_population_acs_5yr, aes(x = Year, y = Hispanic_Latina_Women)) +
  geom_line(color = "blue") +
  geom_point(color = "blue") +
  scale_y_continuous(labels = scales::comma) +
  labs(
    title = "Population of Hispanic/Latina Women in Texas (2009-2022)",
    x = "Year",
    y = "Population",
    caption = "Data Source: U.S. Census Bureau"
  ) +
  theme_minimal()

library(knitr)
Warning: package 'knitr' was built under R version 4.2.3
results_table <- data.frame(
  Year = hispanic_population_acs_5yr$Year,
  Hispanic_Latina_Women = hispanic_population_acs_5yr$Hispanic_Latina_Women
)


library(grid)
library(gridExtra)

Attaching package: 'gridExtra'
The following object is masked from 'package:dplyr':

    combine
table_grob <- tableGrob(results_table)

# Save as PNG
png("population_table.png", width = 800, height = 600)  
grid.newpage()
grid.draw(table_grob)
dev.off()
png 
  2 
4418917 #Pulled from the tables directly to check accuracy 
[1] 4418917
library(RColorBrewer)

# Define color palette
palette <- brewer.pal(3, "Set1")

JPlot<-ggplot(hispanic_population_acs_5yr, aes(x = Year, y = Hispanic_Latina_Women)) +
  geom_line(color = palette[1], alpha = 0.8) +  
  geom_point(color = palette[2], fill = palette[2], size = 5, alpha = 0.8) +  
  geom_label(
    aes(label = paste0(round(Hispanic_Latina_Women / 1000000, 2))),
    fill = "white",
    color = "black",  
    size = 3,  
    label.padding = unit(0.2, "lines"),
    label.r = unit(0.15, "lines"),
    label.size = 0.25,
    nudge_x = 0.25,
    nudge_y = 0.25,
    show.legend = FALSE
  ) +
  scale_y_continuous(labels = scales::comma) +
  labs(
    title = "Population of Hispanic/Latina Women in Texas (2009-2022)",
    x = "Year",
    y = "Population in Millions",
    caption = "Data Source: U.S. Census Bureau, American Community Survey 5-Year Estimates, 2009-2022"
  ) +
  theme_minimal() +
  theme(
    panel.background = element_rect(fill = "white"),
    panel.grid.major = element_line(color = "grey", linewidth = 0.5),
    panel.grid.minor = element_blank(),  # Removed minor grid lines
    axis.title = element_text(size = 12),  # Adjusted axis title font size
    axis.text = element_text(size = 10),  # Adjusted axis text font size
    plot.title = element_text(size = 16),  # Adjusted plot title font size
    plot.caption = element_text(size = 8),  # Adjusted caption font size
  ) +
  scale_x_continuous(breaks = hispanic_population_acs_5yr$Year)  # Adjusted to display all years on the x-axis

print(JPlot)

ggsave("population_growth.png", plot = JPlot, width = 10, height = 6, dpi = 300, bg = "transparent", device = "png")

Texas Latinas By Hispanic Origin

# Load required libraries
library(tidycensus)


# Get the data for Hispanic women in Texas
hispanic_origin_data <- get_acs(
  geography = "state",
  variables = c(
    "B03001_004E", # Mexican
    "B03001_005E", # Puerto Rican
    "B03001_006E", # Cuban
    "B03001_007E", # Dominican
    "B03001_008E", # Central American
    "B03001_009E", # Costa Rican
    "B03001_010E", # Guatemalan
    "B03001_011E", # Honduran
    "B03001_012E", # Nicaraguan
    "B03001_013E", # Panamanian
    "B03001_014E", # Salvadoran
    "B03001_015E", # Other Central American
    "B03001_017E", # Argentinean
    "B03001_018E", # Bolivian
    "B03001_019E", # Chilean
    "B03001_020E", # Colombian
    "B03001_021E", # Ecuadorian
    "B03001_022E", # Paraguayan
    "B03001_023E", # Peruvian
    "B03001_024E", # Uruguayan
    "B03001_025E", # Venezuelan
    "B03001_026E"  # Other South American
  ),
  state = "TX",
  sex = "female", 
  survey = "acs1",
  year = 2022
)
Getting data from the 2022 1-year ACS
The 1-year ACS provides data for geographies with populations of 65,000 and greater.
print(hispanic_origin_data)
# A tibble: 22 × 5
   GEOID NAME  variable   estimate   moe
   <chr> <chr> <chr>         <dbl> <dbl>
 1 48    Texas B03001_004  9674825 55010
 2 48    Texas B03001_005   264937 16950
 3 48    Texas B03001_006   129482 13925
 4 48    Texas B03001_007    38063  5635
 5 48    Texas B03001_008   876530 34811
 6 48    Texas B03001_009    12961  4376
 7 48    Texas B03001_010   151112 15639
 8 48    Texas B03001_011   242067 21850
 9 48    Texas B03001_012    38344  7236
10 48    Texas B03001_013    22621  4191
# ℹ 12 more rows