#install.packages("dplyr")
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
#install.packages("readxl")
library(data.table)
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
df3<- fread("C:/Users/dejmo/OneDrive/Documents/URP Cert/URP 5363- Planning Methods I/Week 6/CA_MSA.csv")

results<-df3 %>%
  group_by(NAME) %>%
  summarize(TotalPolulation = sum(tpop), )

df3$wa <- abs(df3$nhasn/df3$nhasnc-df3$nhwhite/df3$nhwhitec)

HOLC <- fread("C:/Users/dejmo/OneDrive/Documents/URP Cert/URP 5363- Planning Methods I/Week 6/holc_census_tracts.csv")

ave_pct <-HOLC %>%
  group_by(state) %>%
  summarize(avgHOLCarea=mean(holc_area), )

library(ggplot2)

ggplot(HOLC, aes(x=state, y=)) + 
  geom_boxplot()

TX_HOLC<- HOLC[HOLC$state=="TX" & HOLC$holc_grade=="D",]

HOLC_D<-TX_HOLC %>%
  group_by(st_name) %>%
  summarize(CountHOLC_D = n(), )

library(tidycensus)

#https://api.census.gov/data/key_signup.html
census_api_key("b09b67e4355d371d222c288897dceff62a272ccd",)
## To install your API key for use in future sessions, run this function with `install = TRUE`.
var <- c("B17021_002E","B03002_004E") #poverty level, black pop

var <- c(poptotal='B03002_001E', 
         black='B03002_004E', 
         poverty='B17017_002E')


SATX_data <- get_acs(geography = "tract", variables = var,
                                 state = "TX", county = "bexar", year=2018, output = "wide")
## Getting data from the 2014-2018 5-year ACS
SATX_data <- SATX_data %>%
  mutate(black_pct = (black / poptotal) * 100,
    poverty_pct = (poverty / poptotal) * 100)

TX_HOLC$geoid <- as.character(TX_HOLC$geoid)

names(TX_HOLC)[14] <-"GEOID"

SA_HOLC_comb <-merge(SATX_data,TX_HOLC, by="GEOID")

ggplot(SA_HOLC_comb, aes(x= poverty_pct , fill= holc_grade )) + 
  geom_bar()

SATX_HOLC<- HOLC[HOLC$st_name=="San Antonio",]

ggplot(SATX_HOLC, aes(x= st_name, y= holc_grade))+
  geom_boxplot()

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.