I've scoured the internet for my first attempt at creating an interactive map and I've hit a wall. I'm in no way married to this way of creating an interactive map, so if anyone has any other tried and true method that doesn't use plotly, I would love to hear it.
I'm trying to take my panel data and create a "heat map" of how counties change over time. I've simplified for my reproducible example to 3 counties, 3 years, and one variable. I believe the problem is that the thing that I am trying to change over time is the fill for the polygon layer. The outcome of this code is entertaining but obviously not what I'm looking for. Any help, resources, or guidance would be appreciated. Thanks!
library(tidyverse)
wy<-map_data("state", region="wyoming")
county<- map_data("county", region = "wyoming")
#create reprex df
subregion <- rep(c("albany", "big horn", "converse"), each=3)
Year <- rep(c(2004, 2005, 2006), times =3)
Emp<- runif(9)
panel <- data.frame(subregion, Year, Emp)
#Combine this with map data
combined <- merge(panel, county, by= "subregion")
#Create map
x <-ggplot()+
geom_polygon(data=wy, aes(x=long, y=lat, group=group), fill=NA, color="royalblue")+
geom_polygon(data=county, aes(x=long, y=lat, group=group),fill=NA, color="dodgerblue1")+
geom_polygon(data=combined, aes(x=long, y=lat, group=group,fill=Emp, frame = Year))+
theme_void()
ggplotly(x)