This is my first time asking for help so please let me know if I did something wrong. I want to create a map of evictions by county in Ohio. I am using data from the Princeton Eviction lab that I downloaded. I really have no idea how to use it. The geojson file has several features. It has a bunch of variables for different years. For instance, er-01 means the eviction rate in 2001. er-16 means the eviction rate in 2016. The data is from 2000 until 2016. I would like to plot this eviction rate variable for each year. Please help! The following code is something I tried, but I am not sure how to add a legend. Is there an easier way to do this? How can I plot for just one variable and do it for every year?
```{r}
library(leaflet)
library(geojsonio)
library(utils)
library(tidyverse)
download.file("https://raw.githubusercontent.com/amalabdi/milestone_8/master/counties.geojson", "counties.geojson")
geojson <- readLines("counties.geojson", warn = FALSE) %>%
paste(collapse = "\n") %>%
fromJSON(simplifyVector = FALSE)
# Default styles for all features
geojson$style = list(
weight = 1,
color = "#555555",
opacity = 1,
fillOpacity = 0.8
)
# Er-03 is the the eviction rate in 2003
evictionrate <- sapply(geojson$features, function(feat) {
feat$properties$`er-03`
})
# Add a properties$style list to each feature
geojson$features <- lapply(geojson$features, function(feat) {
feat$properties$style <- list(
fillColor = feat$properties$`er-03`
)
feat
})
# Add the now-styled GeoJSON object to the map
leaflet() %>% addGeoJSON(geojson)