#Merge
#Winner from the counties by selecting the candidate with the msot votes
#Plotting the counties by votes
fig <- plot_ly() %>%
add_trace( type = "choropleth",
geojson = counties,
locations = df$fips,
z = df$candidatevotes,
colorscale = "GnBu",
zmin = 0,
zmax = 3028885,
text = df$candidate, # hover mesg
marker = list(line=list(width=0.2))
) %>%
colorbar(title = "Votes") %>%
layout( title = "US 2020 Presidential Election by County",
geo = g)
fig
## [1] 3028885
#Plotting the counties by the winner in each county
election_2020 <- df %>%
select(fips,candidate) %>%
rename(region=fips,value=candidate)
county_choropleth(election_2020,
title ="2020 US Presidential Election Results",
legend = "Winning Candidates")