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.
Using the ACS Data Profile
#create a county FIPS code - 5 digitsa_acs$county<-substr(sa_acs$GEOID, 1, 5)#rename variables and filter missing casessa_acs2<-sa_acs%>%mutate(totpop= DP05_0001E, ppov=DP03_0119PE) %>%# st_transform(crs = 102740)%>%na.omit()
Coordinate Reference System:
User input: NAD83
wkt:
GEOGCRS["NAD83",
DATUM["North American Datum 1983",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4269]]
Create basic map
library(tmap)library(tmaptools)tm_shape(sa_acs2)+tm_polygons("ppov", title="% in Poverty",palette="Blues",style="quantile",n=5 )+tm_format("World",main.title="San Antonio Poverty Estimates (2019) - Quantile Breaks",main.title.position=c('center','top'),main.title.size=1.5,title="Author: Coda Rayo-Garza \nSource: ACS 2019",legend.title.size=1.7,legend.outside=T,legend.text.size=1.2)+tm_scale_bar(position =c("left","bottom"))+tm_compass()
lick [here](https://www.rdocumentation.org/packages/tmap/versions/3.3-3/topics/tm_layout) for more `tmap` aesthetic features.
Click [here](https://www.statology.org/percentile-vs-quartile-vs-quantile/) for a quick discussion on quantile vs. quintile.
Use projected distance calculation
With Transformation
new_sa<-st_transform(sa_acs2, crs =2278)#Extract two tractstwtr<-new_sa%>%filter(GEOID %in%c(48029181820, 48029110600))# get centroid coordinates for two tracts (these two tracts are where UTSA Main and Downtown Campuses are)tr_co<-st_centroid(twtr)
Warning in st_centroid.sf(twtr): st_centroid assumes attributes are constant
over geometries of x
head(tr_co)
Simple feature collection with 2 features and 9 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 2090862 ymin: 13704280 xmax: 2125261 ymax: 13758300
Projected CRS: NAD83 / Texas South Central (ftUS)
GEOID NAME DP05_0001E DP05_0001M
1 48029181820 Census Tract 1818.20, Bexar County, Texas 8305 833
2 48029110600 Census Tract 1106, Bexar County, Texas 5293 423
DP03_0119PE DP03_0119PM geometry county totpop ppov
1 15.2 9.1 POINT (2090862 13758297) 48029 8305 15.2
2 37.8 15.2 POINT (2125261 13704278) 48029 5293 37.8
#Extract two tractsnotransform<-sa_acs2%>%filter(GEOID %in%c(48029181820, 48029110600))# get centroid coordinates for two tracts (these two tracts are where UTSA Main and Downtown Campuses are)no_co<-st_centroid(notransform)
Warning in st_centroid.sf(notransform): st_centroid assumes attributes are
constant over geometries of x
head(no_co)
Simple feature collection with 2 features and 9 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -98.61502 ymin: 29.43017 xmax: -98.50751 ymax: 29.57909
Geodetic CRS: NAD83
GEOID NAME DP05_0001E DP05_0001M
1 48029181820 Census Tract 1818.20, Bexar County, Texas 8305 833
2 48029110600 Census Tract 1106, Bexar County, Texas 5293 423
DP03_0119PE DP03_0119PM geometry county totpop ppov
1 15.2 9.1 POINT (-98.61502 29.57909) 48029 8305 15.2
2 37.8 15.2 POINT (-98.50751 29.43017) 48029 5293 37.8
Without changing the coordinate system, the projected distance is 19555.86 meters. Divided by 1609.34, that’s 12.15148, which is close to the 12.13 we got when we transformed the coordinate system.
# library(qgisprocess) #load the package# qgis_configure() #set up QGIS - find the executable# # qgis_algorithms() lists all the available routines in QGIS# head(qgis_algorithms())