knitr::opts_chunk$set(echo = TRUE)

library("tidycensus")
library("ggplot2")
library("writexl")

census_api_key("0d539976d5203a96fa55bbf4421110d4b3db3648", overwrite=TRUE)
## To install your API key for use in future sessions, run this function with `install = TRUE`.
age_data <- get_decennial(geography = "tract",
                          variables = "P013002",
                          state = "TX",
                          year = 2010)
## Getting data from the 2010 decennial Census
## Using Census Summary File 1
write_xlsx(age_data, "C:/Users/annee/OneDrive - University of Texas at San Antonio/med_age_male_tx.xlsx", col_names = TRUE)

income_data <- get_acs(geography = "tract",
                       variables = "B19013_001E",
                       state = "TX",
                       county = "Bexar", 
                       year = 2010)
## Getting data from the 2006-2010 5-year ACS
hispanic_data <- get_acs(geography = "county",
                         variables = "B03002_012E",
                         state = "TX", 
                         year = 2010)
## Getting data from the 2006-2010 5-year ACS
names(hispanic_data)[names(hispanic_data) == "estimate"] <- "HispanicPop"

names(hispanic_data)
## [1] "GEOID"       "NAME"        "variable"    "HispanicPop" "moe"
ggplot(hispanic_data, aes(y = HispanicPop)) +
  geom_boxplot(fill = "blue", color = "black") +
  labs(title = "Distribution of Hispanic Population Across Texas Counties",
       y = "Hispanic Population")

poverty_data <- get_acs(geography = "tract",
                        variables = "B17001_002E",
                        state = "TX",
                        county = "Bexar",
                        year = 2010)
## Getting data from the 2006-2010 5-year ACS
race_ethnicity_data <- get_acs(geography = "tract", 
                               variables = c("B03002_012E", "B03002_003E", "B03002_004E"), 
                               state = "TX", 
                               county = "Bexar", 
                               year = 2018)
## Getting data from the 2014-2018 5-year ACS
combined_data <- merge(poverty_data, race_ethnicity_data, by = "GEOID")

combined_data$category <- with(combined_data, ifelse(estimate.x > 0 & estimate.y > 0, "In Poverty & Hispanic", ifelse(estimate.x > 0 & estimate.y == 0, "In Poverty & Not Hispanic", "Not in Poverty & Hispanic")))

ggplot(combined_data, aes(x = category)) +
  geom_bar(fill = "purple") +
  labs(title = "Distribution of Categories by Poverty and Ethnicity", x = "Category", y = "Count")

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.