install.packages("jsonlite")
## Installing package into 'C:/Users/Campo/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'jsonlite' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'jsonlite'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Campo\AppData\Local\R\win-library\4.4\00LOCK\jsonlite\libs\x64\jsonlite.dll
## to
## C:\Users\Campo\AppData\Local\R\win-library\4.4\jsonlite\libs\x64\jsonlite.dll:
## Permission denied
## Warning: restored 'jsonlite'
##
## The downloaded binary packages are in
## C:\Users\Campo\AppData\Local\Temp\Rtmp6VYEzB\downloaded_packages
install.packages("writexl")
## Installing package into 'C:/Users/Campo/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'writexl' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Campo\AppData\Local\Temp\Rtmp6VYEzB\downloaded_packages
library(jsonlite)
library(writexl)
url <- "https://api.census.gov/data/2010/dec/sf1?get=P013002&for=tract:*&in=state:48&key=5b0042fd9da940447c2ac386544c406532313aed"
data <- fromJSON(url)
df <- as.data.frame(data[-1, ], stringsAsFactors = FALSE)
colnames(df) <- data[1, ]
write.csv(df, "texas_median_age.csv", row.names = FALSE)
write_xlsx(df, "texas_median_age.xlsx")
install.packages("tidycensus")
## Installing package into 'C:/Users/Campo/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'tidycensus' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Campo\AppData\Local\Temp\Rtmp6VYEzB\downloaded_packages
library(tidycensus)
readRenviron("~/.Renviron")
bexar_income <- get_acs(geography = "tract",
variables = "B19013_001E",
state = "TX",
county = "Bexar",
year = 2018)
## Getting data from the 2014-2018 5-year ACS
head(bexar_income)
## # A tibble: 6 × 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 48029110100 Census Tract 1101, Bexar County, Texas B19013_001 44050 13806
## 2 48029110300 Census Tract 1103, Bexar County, Texas B19013_001 34375 14338
## 3 48029110500 Census Tract 1105, Bexar County, Texas B19013_001 11360 2396
## 4 48029110600 Census Tract 1106, Bexar County, Texas B19013_001 14547 4007
## 5 48029110700 Census Tract 1107, Bexar County, Texas B19013_001 14891 5218
## 6 48029110800 Census Tract 1108, Bexar County, Texas B19013_001 29345 4495
hispanic_population_tx <- get_acs(
geography = "county",
variables = "B03002_012E",
state = "TX",
year = 2018,
survey = "acs5")
## Getting data from the 2014-2018 5-year ACS
head(hispanic_population_tx)
## # A tibble: 6 × 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 48001 Anderson County, Texas B03002_012 10142 NA
## 2 48003 Andrews County, Texas B03002_012 9979 NA
## 3 48005 Angelina County, Texas B03002_012 19174 NA
## 4 48007 Aransas County, Texas B03002_012 6756 NA
## 5 48009 Archer County, Texas B03002_012 727 NA
## 6 48011 Armstrong County, Texas B03002_012 131 69
colnames(hispanic_population_tx)[colnames(hispanic_population_tx) == "estimate"] <- "HispanicPop"
colnames(hispanic_population_tx)
## [1] "GEOID" "NAME" "variable" "HispanicPop" "moe"
install.packages("ggplot2")
## Installing package into 'C:/Users/Campo/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'ggplot2' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Campo\AppData\Local\Temp\Rtmp6VYEzB\downloaded_packages
library(ggplot2)
ggplot(hispanic_population_tx, aes(y = HispanicPop)) +
geom_boxplot() +
labs(title = "Distribution of Hispanic Population Across Texas Counties",
y = "Hispanic Population")

install.packages("tidycenus")
## Installing package into 'C:/Users/Campo/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## Warning: package 'tidycenus' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
library(tidycensus)
bexar_poverty <- get_acs(
geography = "tract",
variables = "B17001_002E",
state = "TX",
county = "Bexar",
year = 2018,
survey = "acs5")
## Getting data from the 2014-2018 5-year ACS
head(bexar_poverty)
## # A tibble: 6 × 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 48029110100 Census Tract 1101, Bexar County, Texas B17001_002 513 178
## 2 48029110300 Census Tract 1103, Bexar County, Texas B17001_002 1057 375
## 3 48029110500 Census Tract 1105, Bexar County, Texas B17001_002 1623 251
## 4 48029110600 Census Tract 1106, Bexar County, Texas B17001_002 1441 387
## 5 48029110700 Census Tract 1107, Bexar County, Texas B17001_002 376 112
## 6 48029110800 Census Tract 1108, Bexar County, Texas B17001_002 432 134
bexar_race_data <- get_acs(
geography = "tract",
variables = c(
Hispanic = "B03002_012E",
White = "B03002_003E",
Black = "B03002_004E"
),
state = "TX",
county = "Bexar",
year = 2018,
survey = "acs5")
## Getting data from the 2014-2018 5-year ACS
head(bexar_race_data)
## # A tibble: 6 × 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 48029110100 Census Tract 1101, Bexar County, Texas B03002_003 999 186
## 2 48029110100 Census Tract 1101, Bexar County, Texas B03002_004 157 76
## 3 48029110100 Census Tract 1101, Bexar County, Texas B03002_012 1832 340
## 4 48029110300 Census Tract 1103, Bexar County, Texas B03002_003 506 150
## 5 48029110300 Census Tract 1103, Bexar County, Texas B03002_004 352 333
## 6 48029110300 Census Tract 1103, Bexar County, Texas B03002_012 2096 400
write.csv(bexar_race_data, "bexar_race_data_2018.csv", row.names = FALSE)
install.packages("writexl")
## Warning: package 'writexl' is in use and will not be installed
library(writexl)
write_xlsx(bexar_race_data, "bexar_race_data_2018.xlsx")
bexar_combined <- merge(bexar_poverty, bexar_race_data, by = c("GEOID", "NAME"))
bexar_combined$PovertyRaceCategory <- paste(bexar_combined$variable.x, bexar_combined$variable.y, sep = "_")
install.packages("ggplot2")
## Warning: package 'ggplot2' is in use and will not be installed
library(ggplot2)
ggplot(bexar_combined, aes(x = PovertyRaceCategory)) +
geom_bar() +
labs(title = "Number of Different Poverty and Race/Ethnicity Categories",
x = "Poverty and Race/Ethnicity Categories",
y = "Count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

options(repos = c(CRAN = "https://cloud.r-project.org"))
path.expand("~")
## [1] "C:/Users/Campo/OneDrive/Documents"
options(repos = c(CRAN = "https://cloud.r-project.org"))
file.edit(file.path("~", ".Rprofile"))