avg_male_age <- get_decennial(geography = "tract", state = "Texas", variables = "P013002", year = 2010)

write_xlsx(x = avg_male_age, path = "/Users/gabrielagarzalong/Desktop/School.xlsx", col_names = TRUE)


bexar_county <- get_acs(geography = "tract", variables = "B19013_001E",
                        state = "TX", county = "Bexar", year = 2018, geometry = TRUE)
hispanic_pop <- get_acs(geography = "county", variables = "B03002_012E",
                        state = "TX", year = 2018, geometry = TRUE)
names(hispanic_pop)[4] <- "HispanicPop"
ggplot(hispanic_pop, aes(y = HispanicPop)) +
  geom_boxplot(fill = "navyblue", color = "black") +
  scale_y_log10() + # I had to chatgpt this part for outliers
  labs(title = "Hispanic Population Across TX Counties", 
       y = "Population",
       x = "")
poverty_pop <- get_acs(geography = "tract", variables = "B17001_002E",
                       state = "TX", county = "Bexar", year = 2018, geometry = TRUE)
var <- c(poptotal='B03002_001E', 
         hispanic='B03002_012E',
         white='B03002_003E',
         black='B03002_004E', 
         poptotal2='B17017_001E',
         poverty='B17017_002E')

hwbpop <- get_acs(geography = "block group", 
                     variables = var,
                     state = "TX", 
                     county = "Bexar", 
                     year = 2018, 
                     output="wide",
                     geometry = TRUE)



hwbpop$black_pct <- hwbpop$black / hwbpop$poptotal
hwbpop$white_pct <- hwbpop$white / hwbpop$poptotal
hwbpop$hispanic_pct <- hwbpop$hispanic / hwbpop$poptotal
hwbpop$poverty_pct <- hwbpop$poverty / hwbpop$poptotal2

hwbpop$Poor <- ifelse(hwbpop$poverty_pct > 0.3, "Poor", "Nonpoor")

hwbpop$Race <- "Other" 
hwbpop$Race[hwbpop$white_pct > 0.5] <- "White"
hwbpop$Race[hwbpop$black_pct > 0.5] <- "Black"
hwbpop$Race[hwbpop$hispanic_pct > 0.5] <- "Hispanic"
combined_data <- combine_vars(poverty_pop, hwbpop, )


hwbpop$race_poverty <- paste0(hwbpop$Poor, hwbpop$Race)

unique(hwbpop$poverty_pop) 

fd <- hwbpop 
  filter(!grepl("Nonpoor", poverty_pop))

unique(fd$poverty_pop)

ggplot(fd, aes(x=race_poverty, fill=race_poverty)) + 
  geom_bar()