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 womenstate ="TX",year = year,survey ="acs5" ) pop_data <-rename(pop_data, Hispanic_Latina_Women = estimate) pop_data$Year <- yearreturn(pop_data)}# Get population data for 2009, 2010, 2011, ..., 2020, 2021, and 2022 using 5-year estimatesyears_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