library(sf)
## Warning: package 'sf' was built under R version 4.4.2
## Linking to GEOS 3.12.2, GDAL 3.9.3, PROJ 9.4.1; sf_use_s2() is TRUE
library(tmap)
## Warning: package 'tmap' was built under R version 4.4.2
## Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
## remotes::install_github('r-tmap/tmap')
library(tidycensus)
## Warning: package 'tidycensus' was built under R version 4.4.2
library(mapview)
library(tigris)
## Warning: package 'tigris' was built under R version 4.4.2
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
#1. Download the "2017 BOND PROGRAM LINE " shapefile data from https://www.sanantonio.gov/GIS/GISDataLinks to an external site. to an external site. and visualize the lines (in green) with bexar county census tracts as the background. (2')
bexar<-tracts(state="Texas", county="Bexar", cb=T)
## Retrieving data for the year 2022
## | | | 0% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |====================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |=========================== | 38% | |=========================== | 39% | |============================ | 40% | |============================ | 41% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |======================================= | 55% | |======================================= | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 80% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 100%
bondlines<-st_read("C:/Users/vmq938/Downloads/BondProjectLines2017/BondProjectLines2017/BondProjectLines2017.shp")
## Reading layer `BondProjectLines2017' from data source
## `C:\Users\vmq938\Downloads\BondProjectLines2017\BondProjectLines2017\BondProjectLines2017.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 69 features and 24 fields
## Geometry type: MULTILINESTRING
## Dimension: XY
## Bounding box: xmin: 2078269 ymin: 13665110 xmax: 2168346 ymax: 13783530
## Projected CRS: NAD83 / Texas South Central (ftUS)
tm_shape(bexar)+
tm_borders()+
tm_shape(bondlines)+
tm_lines(col='green')
#Download the "LIBRARIES " shapefile data from https://www.sanantonio.gov/GIS/GISDataLinks to an external site. to an external site. and visualize the library point (in red) with Bexar county census tracts as the background. Make the map interactive using tmap_mode("view") (2').
libraries<-st_read("C:/Users/vmq938/Downloads/Libraries/Libraries/Libraries.shp")
## Reading layer `Libraries' from data source
## `C:\Users\vmq938\Downloads\Libraries\Libraries\Libraries.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 30 features and 9 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 2075828 ymin: 13669570 xmax: 2170361 ymax: 13779280
## Projected CRS: NAD83 / Texas South Central (ftUS)
tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(bexar)+
tm_borders()+
tm_shape(libraries)+
tm_dots()
#3. Retrieve the census block group data for Travis County, TX using get_acs(), including variables like total population and poverty level. Calculate the ratio of poverty level to total population (poverty/total), and visualize this variable using polygons on a map, applying a custom color palette with a gradient of green to red (e.g., palette = "RdYlGn"). (3')
var<-c(poptotal2='B17017_001E',
poverty='B17017_002E')
st<-"TX"
ct<-"Travis"
cbg<-get_acs(geography="block group", variables=var, count=ct,
state=st, output="wide", year=2021, geometry=TRUE)
## Getting data from the 2017-2021 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.
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## | | | 0% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |== | 4% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========= | 14% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |==================== | 28% | |===================== | 30% | |======================= | 32% | |======================== | 35% | |========================== | 37% | |=========================== | 39% | |============================= | 41% | |=============================== | 44% | |================================ | 46% | |================================== | 48% | |=================================== | 50% | |===================================== | 53% | |======================================= | 55% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 73% | |=================================================== | 74% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100%
cbg$poverty_rate<-cbg$poverty/cbg$poptotal2
tm_shape(cbg)+
tm_polygons(col="poverty_rate",
palette="RdYlGn")
#4. Make the coordinate systems of Bexar Couny census tract and LIBRARY the same, then use overlay analysis to find the census tract for each library. (3')
bexar<-st_transform(bexar, crs=4326)
libraries<-st_transform(libraries,crs = 4326)
lib_tract<-st_intersection(libraries, bexar)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
knitr::opts_chunk$set(echo = TRUE)