output: html_notebook
title: “DEM 7093 Homework 2 using R” author: “Steve Weeks” date: “2/20/2020”
```
library(tidycensus)
library(sf)
## Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
sa_acs<-get_acs(geography = "tract",
state="TX",
county = c("Bexar"),
year = 2017,
variables=c( "DP05_0001E",
"DP03_0119PE") ,
geometry = T, output = "wide")
## Getting data from the 2013-2017 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
#create a county FIPS code - 5 digit
sa_acs$county<-substr(sa_acs$GEOID, 1, 5)
#rename variables and filter missing cases
sa_acs2<-sa_acs%>%
mutate(totpop= DP05_0001E, ppov=DP03_0119PE) %>%
# st_transform(crs = 102740)%>%
na.omit()
st_crs(sa_acs2)
## Coordinate Reference System:
## EPSG: 4269
## proj4string: "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"
ppov_map<-sa_acs2 %>%
mutate(cpov=cut(ppov,breaks = quantile(ppov, na.rm=T, p=seq(0,1,length.out = 6)),include.lowest = T))
library(ggsn)
## Loading required package: ggplot2
## Loading required package: grid
p1<-ggplot(ppov_map, aes(fill = cpov, color = cpov)) +
geom_sf() +
ggtitle("Proportion in poverty",
subtitle = "Bexar County Texas, 2017 - Quantile Breaks")+
scale_fill_brewer(palette = "Reds") +
scale_color_brewer(palette = "Reds")+
theme(axis.text.x = element_blank(), axis.text.y = element_blank())+
north(ppov_map)+
scalebar(ppov_map, location="bottomleft", dist=5, transform = T,dist_unit = "km", model="WGS84", st.size =2 )
p1
new_sa<-st_transform(sa_acs2, crs = 3083)
#Extract two tracts
twtr<-new_sa%>%
filter(GEOID %in% c(48029181820, 48029110600))
# get centroid coordinates for two tracts
tr_co<-st_centroid(twtr)
## Warning in st_centroid.sf(twtr): st_centroid assumes attributes are constant
## over geometries of x
#Measure feet apart
st_distance(tr_co)
## Units: [m]
## [,1] [,2]
## [1,] 0.00 19536.81
## [2,] 19536.81 0.00
##What is the distance between the two points? Is this distance interpretable?
#The distance is 64043 ft using Texas South and 64097 ft using Texas Centric. Yes, the results are interpretable.
##Reproject the layer into a new coordinate system, use NAD83/Texas Centric Albers Equal Area. How do the distances compare between the Texas Centric and Texas South?
#The distances are very similar. The difference between the two is 54 feet.
##In general, why is it important to have an accurate system of projection? How could your results be sensitive to this?
#It is important to have an accurate system of projection so that the map will display correctly. I.e., a projection for Australia used for the United States would have the United States looking very funky.