library(tidyverse)
library(readxl)
library(sf)
library(RColorBrewer)
library(tmap)
library(plotly)

source("functions.R")

Setting up CEJST data

Investigating the relationship between black population and disadvantaged population

## [1] 0.2613683
## 
##  Pearson's product-moment correlation
## 
## data:  j3$blackpct and j3$dispct
## t = 15.382, df = 3227, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2289383 0.2932187
## sample estimates:
##       cor 
## 0.2613683
## 
## Call:
## lm(formula = dispct ~ blackpct, data = j3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -87.078 -31.736  -7.105  28.555  59.323 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 40.67731    0.72590   56.04   <2e-16 ***
## blackpct     0.65299    0.04245   15.38   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 35.37 on 3227 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.06831,    Adjusted R-squared:  0.06802 
## F-statistic: 236.6 on 1 and 3227 DF,  p-value: < 2.2e-16
## tmap mode set to interactive viewing

Setting up of Hsiang climate impact data

Reading state and county GIS files

## Reading layer `cb_2018_us_state_20m' from data source 
##   `/Users/apple/Desktop/UNI/FALL 2023/1. CCA/Class/climate-impacts-lab-v2/cb_2018_us_state_20m.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 52 features and 9 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256
## Geodetic CRS:  NAD83
## Reading layer `cb_2018_us_county_20m' from data source 
##   `/Users/apple/Desktop/UNI/FALL 2023/1. CCA/Class/climate-impacts-lab-v2/cb_2018_us_county_20m.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 3220 features and 9 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256
## Geodetic CRS:  NAD83
## Joining with `by = join_by(geocode)`
## Joining with `by = join_by(geocode)`

Comparing total damages for disadvantaged vs. non-disadvantaged counties

## Simple feature collection with 3 features and 2 fields
## Geometry type: GEOMETRY
## Dimension:     XY
## Bounding box:  xmin: -124.7258 ymin: 24.49813 xmax: -66.9499 ymax: 49.38436
## Geodetic CRS:  NAD83
## # A tibble: 3 × 3
##   disadv average                                                        geometry
##   <lgl>    <dbl>                                                  <GEOMETRY [°]>
## 1 FALSE     3.36 MULTIPOLYGON (((-110.7559 48.2196, -110.6255 48.21973, -110.62…
## 2 TRUE      6.80 MULTIPOLYGON (((-87.63829 39.15749, -87.62538 39.10181, -87.57…
## 3 NA      NaN    POLYGON ((-103.0009 43.47685, -103.0006 43.00026, -102.7921 43…
## Warning in geom_point(aes(x = dispct, y = total, col = disadv, label = cname2)):
## Ignoring unknown aesthetics: label
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (`stat_smooth()`).
## Warning in geom_point(data = c2, aes(x = dispct, y = total, col = disadv, :
## Ignoring unknown aesthetics: label
## Warning in geom_point(data = (c2 %>% filter(statefp == "13")), aes(x = dispct, :
## Ignoring unknown aesthetics: label
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (`stat_smooth()`).

Creating maps of disadvantaged counties and climate damages

## tmap mode set to interactive viewing
## Variable(s) "total" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.