Same-sex households in Texas, 2020

Author

Kaitlan Wong

# Map: same-sex households in Texas by county
tx_samesex <- get_decennial(
  geography = "county",
  variables = c(married = "DP1_0116P",
                cohabiting = "DP1_0118P"),
  sumfile = "dp",
  output = "wide",
  year = 2020,
  state = "TX",
  geometry = TRUE
) %>% 
  mutate(percent = married + cohabiting)
Getting data from the 2020 decennial Census
Using the Demographic Profile
Note: 2020 decennial Census data use differential privacy, a technique that
introduces errors into data to preserve respondent confidentiality.
ℹ Small counts should be interpreted with caution.
ℹ See https://www.census.gov/library/fact-sheets/2021/protecting-the-confidentiality-of-the-2020-census-redistricting-data.html for additional guidance.
This message is displayed once per session.
# Print the resulting dataset
print(tx_samesex)
Simple feature collection with 254 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -106.6456 ymin: 25.83738 xmax: -93.50829 ymax: 36.5007
Geodetic CRS:  NAD83
# A tibble: 254 × 6
   GEOID NAME               married cohabiting                  geometry percent
 * <chr> <chr>                <dbl>      <dbl>        <MULTIPOLYGON [°]>   <dbl>
 1 48029 Bexar County, Tex…     0.2        0.2 (((-98.80655 29.69071, -…     0.4
 2 48423 Smith County, Tex…     0.1        0.1 (((-95.59454 32.68703, -…     0.2
 3 48201 Harris County, Te…     0.2        0.2 (((-94.97839 29.68365, -…     0.4
 4 48471 Walker County, Te…     0.1        0.1 (((-95.86227 30.86536, -…     0.2
 5 48257 Kaufman County, T…     0.2        0.1 (((-96.52941 32.54528, -…     0.3
 6 48223 Hopkins County, T…     0.1        0.1 (((-95.86333 33.04989, -…     0.2
 7 48321 Matagorda County,…     0.1        0.1 (((-96.37833 28.39078, -…     0.2
 8 48473 Waller County, Te…     0.1        0   (((-96.19178 30.13842, -…     0.1
 9 48215 Hidalgo County, T…     0.1        0.1 (((-98.5853 26.26027, -9…     0.2
10 48323 Maverick County, …     0.1        0   (((-100.6675 29.08429, -…     0.1
# ℹ 244 more rows
map <- ggplot(tx_samesex, aes(fill = percent)) + 
    geom_sf(color = NA) + 
    theme_void() + 
    scale_fill_viridis_c(option = "magma") + 
    labs(title = "Percent Same-Sex Households in Texas by County, 2020",
      subtitle = "Every Texan analysis of U.S. Census Bureau 2020 DHC and DP files",
      fill = "Percent")

# Display the statewide map
print(map)

# Save the statewide map
ggsave(filename = "same_sex_households_tx.png", plot = map, dpi = 300)
Saving 7 x 5 in image
# Function to create map by tract for select counties
create_county_map <- function(county_name) {
  print(paste("Creating map for", county_name, "County"))
  
  county_samesex <- get_decennial(
    geography = "tract",
    variables = c(married = "DP1_0116P",
                  cohabiting = "DP1_0118P"),
    sumfile = "dp",
    output = "wide",
    year = 2020,
    state = "TX",
    county = county_name,
    geometry = TRUE
  )
  
  print(county_samesex)
  
  county_samesex <- county_samesex %>%
    dplyr::mutate(percent = married + cohabiting)

  ggplot(county_samesex, aes(fill = percent)) + 
    geom_sf(color = NA) + 
    theme_void() + 
    scale_fill_viridis_c(option = "magma") + 
    labs(title = paste("Percent Same-Sex Households in", county_name, "County, 2020"),
         subtitle = "Every Texan analysis of U.S. Census Bureau 2020 DHC and DP files",
         fill = "Percent")
}

# Create maps for multiple counties
counties <- c("Travis", "Dallas", "Bexar")  # Add more counties as needed

for (county in counties) {
  tryCatch({
    map <- create_county_map(county)
    print(map)
  }, error = function(e) {
    print(paste("Error in creating map for", county, ":"))
    print(e)
  })
}
[1] "Creating map for Travis County"
Getting data from the 2020 decennial Census
Using the Demographic Profile
Simple feature collection with 290 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -98.17298 ymin: 30.02345 xmax: -97.36954 ymax: 30.62825
Geodetic CRS:  NAD83
# A tibble: 290 × 5
   GEOID       NAME                 married cohabiting                  geometry
   <chr>       <chr>                  <dbl>      <dbl>        <MULTIPOLYGON [°]>
 1 48453002201 Census Tract 22.01;…     0.5        0.2 (((-97.67323 30.32572, -…
 2 48453000304 Census Tract 3.04; …     0.9        0.8 (((-97.72461 30.307, -97…
 3 48453001307 Census Tract 13.07;…     0.7        0.7 (((-97.77566 30.23001, -…
 4 48453002002 Census Tract 20.02;…     0.4        0.6 (((-97.79099 30.22575, -…
 5 48453002413 Census Tract 24.13;…     0.1        0.3 (((-97.74501 30.18975, -…
 6 48453001606 Census Tract 16.06;…     0.4        0   (((-97.7649 30.30534, -9…
 7 48453000801 Census Tract 8.01; …     0.5        0.2 (((-97.70904 30.26539, -…
 8 48453043100 Census Tract 431; T…     0.4        0   (((-97.70011 30.35765, -…
 9 48453042700 Census Tract 427; T…     0.3        0.2 (((-97.64754 30.46136, -…
10 48453040200 Census Tract 402; T…     0.5        0.5 (((-97.69505 30.32187, -…
# ℹ 280 more rows
[1] "Creating map for Dallas County"
Getting data from the 2020 decennial Census
Using the Demographic Profile

Simple feature collection with 645 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -97.03868 ymin: 32.54521 xmax: -96.51698 ymax: 32.98969
Geodetic CRS:  NAD83
# A tibble: 645 × 5
   GEOID       NAME                 married cohabiting                  geometry
   <chr>       <chr>                  <dbl>      <dbl>        <MULTIPOLYGON [°]>
 1 48113019016 Census Tract 190.16…     0.4        0.4 (((-96.75692 32.92422, -…
 2 48113018203 Census Tract 182.03…     0.1        0   (((-96.621 32.90811, -96…
 3 48113018402 Census Tract 184.02…     0.2        0.2 (((-96.64822 32.87114, -…
 4 48113000201 Census Tract 2.01; …     0.4        0.3 (((-96.76156 32.82989, -…
 5 48113001502 Census Tract 15.02;…     0.4        0.7 (((-96.77688 32.79391, -…
 6 48113012701 Census Tract 127.01…     0.3        0.1 (((-96.68448 32.84424, -…
 7 48113009104 Census Tract 91.04;…     0.2        0.1 (((-96.70028 32.74901, -…
 8 48113013010 Census Tract 130.10…     0.3        0.2 (((-96.69384 32.87418, -…
 9 48113018204 Census Tract 182.04…     0.2        0.1 (((-96.63102 32.90216, -…
10 48113005400 Census Tract 54; Da…     0.4        0.2 (((-96.8266 32.72331, -9…
# ℹ 635 more rows
[1] "Creating map for Bexar County"
Getting data from the 2020 decennial Census
Using the Demographic Profile

Simple feature collection with 375 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -98.80655 ymin: 29.11444 xmax: -98.1169 ymax: 29.76071
Geodetic CRS:  NAD83
# A tibble: 375 × 5
   GEOID       NAME                 married cohabiting                  geometry
   <chr>       <chr>                  <dbl>      <dbl>        <MULTIPOLYGON [°]>
 1 48029171601 Census Tract 1716.0…     0.1        0.1 (((-98.62398 29.41355, -…
 2 48029180604 Census Tract 1806.0…     0.3        0.4 (((-98.58517 29.47894, -…
 3 48029151600 Census Tract 1516; …     0.1        0.1 (((-98.50388 29.34895, -…
 4 48029150502 Census Tract 1505.0…     0.1        0.2 (((-98.53415 29.37502, -…
 5 48029181712 Census Tract 1817.1…     0.2        0.2 (((-98.66604 29.48512, -…
 6 48029180102 Census Tract 1801.0…     0.6        0.4 (((-98.54874 29.46871, -…
 7 48029121508 Census Tract 1215.0…     0.3        0.2 (((-98.37162 29.5104, -9…
 8 48029121404 Census Tract 1214.0…     0.1        0.2 (((-98.4041 29.47818, -9…
 9 48029191505 Census Tract 1915.0…     0.4        0.1 (((-98.56706 29.55566, -…
10 48029190504 Census Tract 1905.0…     0.3        0.5 (((-98.516 29.46644, -98…
# ℹ 365 more rows

# Save maps of selected counties
counties <- c("Travis", "Dallas", "Bexar")

for (county in counties) {
  map <- create_county_map(county)
  filename <- paste(county, "map.png", sep = "_")
  ggsave(filename, map, dpi = 300)
}
[1] "Creating map for Travis County"
Getting data from the 2020 decennial Census
Using the Demographic Profile
Simple feature collection with 290 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -98.17298 ymin: 30.02345 xmax: -97.36954 ymax: 30.62825
Geodetic CRS:  NAD83
# A tibble: 290 × 5
   GEOID       NAME                 married cohabiting                  geometry
   <chr>       <chr>                  <dbl>      <dbl>        <MULTIPOLYGON [°]>
 1 48453002201 Census Tract 22.01;…     0.5        0.2 (((-97.67323 30.32572, -…
 2 48453000304 Census Tract 3.04; …     0.9        0.8 (((-97.72461 30.307, -97…
 3 48453001307 Census Tract 13.07;…     0.7        0.7 (((-97.77566 30.23001, -…
 4 48453002002 Census Tract 20.02;…     0.4        0.6 (((-97.79099 30.22575, -…
 5 48453002413 Census Tract 24.13;…     0.1        0.3 (((-97.74501 30.18975, -…
 6 48453001606 Census Tract 16.06;…     0.4        0   (((-97.7649 30.30534, -9…
 7 48453000801 Census Tract 8.01; …     0.5        0.2 (((-97.70904 30.26539, -…
 8 48453043100 Census Tract 431; T…     0.4        0   (((-97.70011 30.35765, -…
 9 48453042700 Census Tract 427; T…     0.3        0.2 (((-97.64754 30.46136, -…
10 48453040200 Census Tract 402; T…     0.5        0.5 (((-97.69505 30.32187, -…
# ℹ 280 more rows
Saving 7 x 5 in image
[1] "Creating map for Dallas County"
Getting data from the 2020 decennial Census
Using the Demographic Profile
Simple feature collection with 645 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -97.03868 ymin: 32.54521 xmax: -96.51698 ymax: 32.98969
Geodetic CRS:  NAD83
# A tibble: 645 × 5
   GEOID       NAME                 married cohabiting                  geometry
   <chr>       <chr>                  <dbl>      <dbl>        <MULTIPOLYGON [°]>
 1 48113019016 Census Tract 190.16…     0.4        0.4 (((-96.75692 32.92422, -…
 2 48113018203 Census Tract 182.03…     0.1        0   (((-96.621 32.90811, -96…
 3 48113018402 Census Tract 184.02…     0.2        0.2 (((-96.64822 32.87114, -…
 4 48113000201 Census Tract 2.01; …     0.4        0.3 (((-96.76156 32.82989, -…
 5 48113001502 Census Tract 15.02;…     0.4        0.7 (((-96.77688 32.79391, -…
 6 48113012701 Census Tract 127.01…     0.3        0.1 (((-96.68448 32.84424, -…
 7 48113009104 Census Tract 91.04;…     0.2        0.1 (((-96.70028 32.74901, -…
 8 48113013010 Census Tract 130.10…     0.3        0.2 (((-96.69384 32.87418, -…
 9 48113018204 Census Tract 182.04…     0.2        0.1 (((-96.63102 32.90216, -…
10 48113005400 Census Tract 54; Da…     0.4        0.2 (((-96.8266 32.72331, -9…
# ℹ 635 more rows
Saving 7 x 5 in image
[1] "Creating map for Bexar County"
Getting data from the 2020 decennial Census
Using the Demographic Profile
Simple feature collection with 375 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -98.80655 ymin: 29.11444 xmax: -98.1169 ymax: 29.76071
Geodetic CRS:  NAD83
# A tibble: 375 × 5
   GEOID       NAME                 married cohabiting                  geometry
   <chr>       <chr>                  <dbl>      <dbl>        <MULTIPOLYGON [°]>
 1 48029171601 Census Tract 1716.0…     0.1        0.1 (((-98.62398 29.41355, -…
 2 48029180604 Census Tract 1806.0…     0.3        0.4 (((-98.58517 29.47894, -…
 3 48029151600 Census Tract 1516; …     0.1        0.1 (((-98.50388 29.34895, -…
 4 48029150502 Census Tract 1505.0…     0.1        0.2 (((-98.53415 29.37502, -…
 5 48029181712 Census Tract 1817.1…     0.2        0.2 (((-98.66604 29.48512, -…
 6 48029180102 Census Tract 1801.0…     0.6        0.4 (((-98.54874 29.46871, -…
 7 48029121508 Census Tract 1215.0…     0.3        0.2 (((-98.37162 29.5104, -9…
 8 48029121404 Census Tract 1214.0…     0.1        0.2 (((-98.4041 29.47818, -9…
 9 48029191505 Census Tract 1915.0…     0.4        0.1 (((-98.56706 29.55566, -…
10 48029190504 Census Tract 1905.0…     0.3        0.5 (((-98.516 29.46644, -98…
# ℹ 365 more rows
Saving 7 x 5 in image
# Sort the dataset by percent in descending order
tx_samesex_sorted <- tx_samesex[order(-tx_samesex$percent), ]

# Convert to data frame
tx_samesex_sorted <- as.data.frame(tx_samesex_sorted)

# Export the sorted dataset to an Excel file
write_xlsx(tx_samesex_sorted, path = "same_sex_households_by_county.xlsx", col_names = TRUE)