For this project, we utilize the Gini Index which is a summary measure of income inequality to see the dispersion of income accross the United States. Gender FIPS Code Name of Institution Number of degrees awarded masters and doctoral level 2013-2017
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
##census_api_key(key="95a91ddea073de2c8d473e622e3cb99007afdfee", install=T)
Extract from ACS summary file data profile variables from 2015 for all states The data profile tables are very useful because they contain lots of pre-calculated variables.
allstates_acs<-get_acs(geography = "state", year = 2015,
variables=c( "B19083_001"),
summary_var = "B01001_001",
geometry = T, output = "wide")
## Getting data from the 2011-2015 5-year ACS
#create a state FIPS code - 5 digit
allstates_acs$state<-substr(allstates_acs$GEOID, 1, 5)
#rename variables and filter missing cases
allstates_acs2<-allstates_acs%>%
mutate(gini1= B19083_001E, gini2=B19083_001M)
#st_transform(crs = 102740)
class(allstates_acs2)
## [1] "sf" "data.frame"
library(classInt)
#devtools::install_github("tidyverse/ggplot2",force=TRUE)
#devtools::install_github("oswaldosantos/ggsn",force=TRUE)
#devtools::install_github("jannes-m/RQGIS",force=TRUE)
library(dplyr)
library(ggplot2)
library(RQGIS)
## Loading required package: reticulate
library(ggsn)
## Loading required package: grid
library(classInt)
ginimap<-allstates_acs2 %>%
mutate(cv_cut=cut(gini1, breaks = quantile(gini1, na.rm=T, p=seq(0,1,length.out = 6)),include.lowest = T))
library(ggsn)
p1<-ggplot(ginimap, aes( fill=cv_cut, color=cv_cut))+
geom_sf() +
ggtitle("GINI Coefficient, 2015 ",
subtitle = "U.S. States")+
scale_fill_brewer(palette = "Blues") +
scale_color_brewer(palette = "Blues")+
#scale_fill_manual(values=myfil)+
theme(axis.text.x = element_blank(), axis.text.y = element_blank())+
north(ginimap)+
scalebar(ginimap, dist = 5, dd2km =T, model="GRS80", st.size = 2)
p1
##PART II. IPEDS DATA
library(tigris)
## To enable
## caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
##
## Attaching package: 'tigris'
## The following object is masked from 'package:graphics':
##
## plot
library(sp)
library(tidyverse)
data(fips_codes)
ipedsdata<- read.csv("C:/Users/PCMcC/Documents/GIS Class/Assignments/Data_6-24-2018---118.csv", header = TRUE)
names(ipedsdata) #print the column names
## [1] "UnitID"
## [2] "Institution.Name"
## [3] "Grand.total..C2016_C..Master.s.degree."
## [4] "Grand.total.men..C2016_C..Master.s.degree."
## [5] "Grand.total.women..C2016_C..Master.s.degree."
## [6] "Grand.total..C2016_C..Doctor.s.degree."
## [7] "Grand.total.men..C2016_C..Doctor.s.degree."
## [8] "Grand.total.women..C2016_C..Doctor.s.degree."
## [9] "Institution..entity..name..HD2015."
## [10] "ZIP.code..HD2015."
## [11] "Latitude.location.of.institution..HD2015."
## [12] "Longitude.location.of.institution..HD2015."
## [13] "City.location.of.institution..HD2015."
## [14] "FIPS.state.code..HD2017."
## [15] "X"
ipedsdata2<-ipedsdata%>%
transmute(UnitID=UnitID, longitude= Longitude.location.of.institution..HD2015.,latitude=Latitude.location.of.institution..HD2015.,Total_Masters=Grand.total..C2016_C..Master.s.degree.,Total_Masters_Men=Grand.total.men..C2016_C..Master.s.degree.,Total_Masters_Women=Grand.total.women..C2016_C..Master.s.degree.,Total_Doctoral=Grand.total..C2016_C..Doctor.s.degree., Total_Doctoral_Men=Grand.total.men..C2016_C..Doctor.s.degree., Total_Doctoral_Women=Grand.total.women..C2016_C..Doctor.s.degree., Zip_Code=ZIP.code..HD2015., City=City.location.of.institution..HD2015., FIPS_State=FIPS.state.code..HD2017., Institution.Name=Institution..entity..name..HD2015.) %>%
# st_transform(crs = 102740)%>%
filter(complete.cases(longitude,latitude,Total_Masters,Total_Masters_Women,Total_Masters_Men))
ipedsdata2[is.na(ipedsdata2)] <- 0
library(sf)
library(RQGIS)
library(mapview)
edupoints<-st_as_sf(ipedsdata2, coords=c("longitude","latitude"), crs=4269, agr="constant")
#I name it the name of the first cell.
mapview(edupoints["UnitID"])
colnames(edupoints)
## [1] "UnitID" "Total_Masters" "Total_Masters_Men"
## [4] "Total_Masters_Women" "Total_Doctoral" "Total_Doctoral_Men"
## [7] "Total_Doctoral_Women" "Zip_Code" "City"
## [10] "FIPS_State" "Institution.Name" "geometry"
R is good at reading these data in, projecting them and we can also write the data out again, in case we wanted to share them or use them in QGIS.
st_write(edupoints,dsn = "C:/Users/PCMcC/Documents/GIS Class", layer = "ipeds_proj2", driver = "ESRI Shapefile", delete_dsn = T )
st_write(ginimap,dsn = "C:/Users/PCMcC/Documents/GIS Class/shapefiles", layer = "gini_proj3", driver = "ESRI Shapefile", delete_dsn = T )
edupoints<-st_as_sf(ipedsdata2, coords=c("longitude","latitude"), crs=4269, agr="constant")
#I name it the name of the first cell.
mapview(edupoints,zcol=c("Total_Masters_Women", "Total_Masters_Men", "Total_Masters","Total_Doctoral", "Total_Doctoral_Men","Total_Doctoral_Women"), legend = TRUE)