Couple days ago, I just saw the news saying than the unemployment rate in April dropping to 3.6 percent—the lowest unemployment rate since December 1969, according to the Bureau of Labor Statistics’ (BLS) household survey.
Therefore, in this homework I want to take a look at the unemployment rate from 2016 to 2017 which is the latest data in this dataset.
library(tidyverse)
## ── Attaching packages ────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.3.0
## ✔ tibble 2.0.1 ✔ dplyr 0.8.0.1
## ✔ tidyr 0.8.2 ✔ stringr 1.3.1
## ✔ readr 1.3.1 ✔ forcats 0.3.0
## ── Conflicts ───────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.1.3, PROJ 4.9.3
library(tmap)
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(spdep)
## Loading required package: sp
## Loading required package: spData
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
library(tmaptools)
library(dplyr)
library(tidyr)
library(readr)
options(tigris_use_cache = TRUE)
options(tigris_progress_bar = FALSE)
options(tidycensus_progress_ba = FALSE)
countyMap <- st_read('/Users/Jessica/rsconnect/documents/tl_2016_us_county-5/tl_2016_us_county.shp', stringsAsFactors = FALSE)
## Reading layer `tl_2016_us_county' from data source `/Users/Jessica/rsconnect/documents/tl_2016_us_county-5/tl_2016_us_county.shp' using driver `ESRI Shapefile'
## Simple feature collection with 3233 features and 17 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.44106
## epsg (SRID): 4269
## proj4string: +proj=longlat +datum=NAD83 +no_defs
names(countyMap)
## [1] "STATEFP" "COUNTYFP" "COUNTYNS" "GEOID" "NAME" "NAMELSAD"
## [7] "LSAD" "CLASSFP" "MTFCC" "CSAFP" "CBSAFP" "METDIVFP"
## [13] "FUNCSTAT" "ALAND" "AWATER" "INTPTLAT" "INTPTLON" "geometry"
countyData <- read.csv("/Users/Jessica/Desktop/unemployment.csv", stringsAsFactors = FALSE)
names(countyData)
## [1] "FIPStxt"
## [2] "State"
## [3] "Area_name"
## [4] "Rural_urban_continuum_code_2013"
## [5] "Urban_influence_code_2013"
## [6] "Metro_2013"
## [7] "Civilian_labor_force_2007"
## [8] "Employed_2007"
## [9] "Unemployed_2007"
## [10] "Unemployment_rate_2007"
## [11] "Civilian_labor_force_2008"
## [12] "Employed_2008"
## [13] "Unemployed_2008"
## [14] "Unemployment_rate_2008"
## [15] "Civilian_labor_force_2009"
## [16] "Employed_2009"
## [17] "Unemployed_2009"
## [18] "Unemployment_rate_2009"
## [19] "Civilian_labor_force_2010"
## [20] "Employed_2010"
## [21] "Unemployed_2010"
## [22] "Unemployment_rate_2010"
## [23] "Civilian_labor_force_2011"
## [24] "Employed_2011"
## [25] "Unemployed_2011"
## [26] "Unemployment_rate_2011"
## [27] "Civilian_labor_force_2012"
## [28] "Employed_2012"
## [29] "Unemployed_2012"
## [30] "Unemployment_rate_2012"
## [31] "Civilian_labor_force_2013"
## [32] "Employed_2013"
## [33] "Unemployed_2013"
## [34] "Unemployment_rate_2013"
## [35] "Civilian_labor_force_2014"
## [36] "Employed_2014"
## [37] "Unemployed_2014"
## [38] "Unemployment_rate_2014"
## [39] "Civilian_labor_force_2015"
## [40] "Employed_2015"
## [41] "Unemployed_2015"
## [42] "Unemployment_rate_2015"
## [43] "Civilian_labor_force_2016"
## [44] "Employed_2016"
## [45] "Unemployed_2016"
## [46] "Unemployment_rate_2016"
## [47] "Civilian_labor_force_2017"
## [48] "Employed_2017"
## [49] "Unemployed_2017"
## [50] "Unemployment_rate_2017"
## [51] "Median_Household_Income_2017"
## [52] "Med_HH_Income_Percent_of_State_Total_2017"
countyData=countyData%>%
rename("GEOID"="FIPStxt")
countyMap$GEOID=parse_integer(countyMap$GEOID)
mergedData=left_join(countyMap,countyData,by="GEOID")
USA =mergedData %>%
filter(STATEFP != "02") %>%
filter(STATEFP != "15") %>%
filter(STATEFP != "60") %>%
filter(STATEFP != "66") %>%
filter(STATEFP != "69") %>%
filter(STATEFP != "72") %>%
filter(STATEFP != "78")
state_border=USA%>%
aggregate_map(by="STATEFP")
ggplot(USA,aes(x=Unemployment_rate_2016))+geom_density(fill="lightblue")+geom_density(aes(x=Unemployment_rate_2017),fill="pink",alpha=.4)+labs(title = "Unemployment Rate by Year",x="Unemployment Rate",y="Density")
Pictured above is an overlapped density distribution of the United States’ total employment rate. 2016 is represented in light blue and 2017 is in pink.
tm_shape(USA,projection = 2163)+tm_fill( col=c("Unemployment_rate_2016","Unemployment_rate_2017"),palette="Reds",midpoint=10,border.col = "grey", border.alpha = .3,title=c("Unemployment Rate 2016","Unemployment Rate 2017"))+tm_shape(state_border)+ tm_borders(lwd = .28, col = "black", alpha = 1)+tm_style("classic")+tm_layout(panel.labels=c("2016","2017"),legend.position = c("left","bottom"))
By looking at the map from 2016 to 2017, we notice that the map gets lighter overall, indicating lower overall levels of unemployment. However, by analyzing the maps closely, we notice places that indicate a positive unemployment rate growth from 2016 to 2017.
USA=USA%>%
group_by(GEOID)%>%
mutate(URDiff=Unemployment_rate_2017-Unemployment_rate_2016)
tm_shape(USA,projection = 2163)+tm_polygons( 'URDiff',midpoint=0,palette="-RdBu",border.col = "grey", border.alpha = .3,title="Change Rate")+tm_shape(state_border)+ tm_borders(lwd = .28, col = "black", alpha = 1)
NY=filter(USA,STATEFP=="36")
tm_shape(NY)+tm_polygons( 'URDiff',midpoint=0,palette="-RdBu",border.col = "grey", border.alpha = .3,title="Change Rate")+tm_text("NAME",size = "AREA")+tm_shape(state_border)+ tm_borders(lwd = .28, col = "black", alpha = 1)
Here we see while NYC has made improvements in levels of unemployment, virtually all other counties have actually seen slight to no improvements in the unemployment rate. Hamilton county is especially worse off compared to the rest of New York.
AL=filter(USA,STATEFP=="01")
tm_shape(AL)+tm_polygons( 'URDiff',midpoint=0,palette="-RdBu",border.col = "grey", border.alpha = .3,title="Change Rate")+tm_text("NAME",size = "AREA")+tm_shape(state_border)+ tm_borders(lwd = .28, col = "black", alpha = 1)
Montana offers us a different look at unemployment change. Looking at the map, we can see how all of the counties in Alabama are experiencing lower unemployment rates in 2017.
The map givng us another perspective of the unemployment rate. While the country is trending towards lower unemployment rates, some areas just aren’t progressing as equally as others. This insight is what we gain from spatial mapping.
In the example below, when specifying cb=FALSE, we get a lower detailed map.
countyMap=counties(cb = FALSE )
USA=USA%>%
group_by(GEOID)%>%
mutate(URDiff=Unemployment_rate_2017-Unemployment_rate_2016)
NY=filter(USA,STATEFP=="36")
tm_shape(NY)+tm_polygons( 'URDiff',midpoint=0,palette="-RdBu",border.col = "grey", border.alpha = .3,title="Change Rate")+tm_text("NAME",size = "AREA")+tm_shape(state_border)+ tm_borders(lwd = .28, col = "black", alpha = 1)