library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(gplots)
##
## Attaching package: 'gplots'
##
## The following object is masked from 'package:stats':
##
## lowess
library(maps)
##
## Attaching package: 'maps'
##
## The following object is masked from 'package:purrr':
##
## map
library(ggmap)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(RColorBrewer)
library(leaflet)
library(ggthemes)
library(usdata)
library(htmltools)
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
geojson_path <- "Desktop/washsh_area.geojson"
county_data <- st_read(geojson_path)
## Reading layer `Washington_Counties_with_Natural_Shoreline___washsh_area' from data source `/Users/baileylengfelder/Desktop/washsh_area.geojson' using driver `GeoJSON'
## Simple feature collection with 39 features and 7 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -124.7331 ymin: 45.54373 xmax: -116.9152 ymax: 49.00253
## Geodetic CRS: WGS 84
csv_path <- "Desktop/WACounties.csv"
# Load the selected CSV file
data <- read.csv(csv_path)
countywa <- filter(county,
state=='Washington')
countywa$name<- sub(" County$","",countywa$name)
colnames(countywa)[colnames(countywa) == "name"] <- "COUNTYLABEL"
county_data1 <- county_data %>%
semi_join(data, by = c("COUNTYLABEL" = "COUNTYLABEL"))
county_data2 <- county_data1 %>%
full_join(countywa, by = c("COUNTYLABEL" = "COUNTYLABEL"))
ggplot() +
geom_sf(data = county_data2, aes(fill = unemployment_rate)) +
scale_fill_viridis_c() +
labs(title = "Washington State Unemployment by County",
fill = "Unemployment Rate") +
theme_minimal()
Created by Bailey Lengfelder
map <- leaflet() %>%
addTiles()
colors <- colorNumeric(palette = "PuRd", domain = county_data2$unemployment_rate)
map <- map %>%
addPolygons(
data = county_data2,
fillColor = ~colors(unemployment_rate),
fillOpacity = 0.7,
color = "white",
weight = 1,
highlight = highlightOptions(
weight = 3,
color = "black",
bringToFront = TRUE
),
popup = ~paste("<strong>County: </strong>", COUNTYLABEL, "<br><strong>Unemployment Rate:</strong> ", unemployment_rate, "%"),
label = ~paste("Unemployment Rate: ", unemployment_rate, "%"))
map <- map %>%
addLegend(
pal = colors,
values = county_data2$unemployment_rate,
position = "bottomright",
title = "Unemployment Rate (%)",
labFormat = labelFormat()
)
map