I am trying to create a map showing generation capacity by county with leaflet. There can be multiple generating units per county, but I thought that would not be an issue for mapping county capacity. I pulled county geometries from tidycensus, and joined those with the dataset for county generation capacity. I have included my code below. Any help/insight would be much appreciated!
Texas_counties <- get_acs(state = "TX", geography = "county",
variables = c(totalpop = "B01003_001"), geometry = TRUE)
Texas_counties <- Texas_counties %>%
mutate(NAME = gsub(" County, Texas", "", NAME))
Texas_counties <- Texas_counties %>%
mutate(NAME = toupper(NAME))
Texas_counties$GEOID <- NULL
Texas_counties$variable <- NULL
Texas_counties$estimate <- NULL
Texas_counties$moe <- NULL
colnames(Texas_counties)[1] <- "COUNTY"
ERCOT_counties <- left_join(ERCOT_report, Texas_counties, by = "COUNTY")
pal <- colorNumeric("viridis", NULL)
leaflet(ERCOT_counties) %>%
addTiles() %>%
addPolygons(data = geometry, stroke = FALSE, smoothFactor = 0.3,
fillOpacity = 1,
fillColor = ~pal(COUNTY_CAPACITY))
Error in polygonData.default(data) : Don't know how to get path data from object of class standardGeneric
data = geometry
toaddPolygons
. Where isgeometry
coming from? You don't seem to have that defined anywhere. Maybe you meantdata = ~geometry
? – MrFlick~
before the name to let leaflet know the values are coming from the data object – MrFlick