For this project, I wanted to compare how smoothed rates compare to the raw (unadjusted) rates when conducting a geospatial visualization. Data comes from the U.S. census in 1960, 1970, 1980, and 1990.
All credit for the instructions and data go to Crime Mapping and Spatial Data Analysis using R by Juanjo Medina and Reka Solymosi.
Code can be found below.
library(readr)
library(dplyr)
library(janitor)
library(skimr)
library(sf)
library(tmap)
library(tmaptools)
library(DCluster)
library(geodaData)
library(RColorBrewer)
data("ncovr")
ncovr_sp <- as(ncovr, "Spatial")
w_nb <- poly2nb(ncovr_sp, row.names=ncovr_sp$FIPSNO)
eb2 <- EBlocal(ncovr$HC60, ncovr$PO60, w_nb)
ncovr$HR60EBSL <- eb2$est * 100000
tmap_mode("plot")
current_style <- tmap_style("col_blind")
map1<- tm_shape(ncovr) +
tm_fill("HR60", style="quantile",
title = "Raw rate",
palette = "YlOrRd") +
tm_layout(legend.position = c("left", "bottom"),
legend.title.size = 0.8, legend.text.size = 0.5)
map2<- tm_shape(ncovr) +
tm_fill("HR60EBSL", style="quantile",
title = "Local Smooth",
palette = "YlOrRd") +
tm_layout(legend.position = c("left", "bottom"),
legend.title.size = 0.8, legend.text.size = 0.5)
tmap_arrange(map1, map2)