## Warning: package 'leaflet' was built under R version 3.4.3
## Warning: package 'rvest' was built under R version 3.4.3
## Loading required package: xml2
## Warning: package 'xml2' was built under R version 3.4.3
Using publically availabe voting data for the state of South Carolina (available at https://www.scvotes.org/cgi-bin/scsec/vothist?election=vhppd16®vote=VOT) and latitude/ longitude values for each county of the state (available at https://www.census.gov/geo/maps-data/data/gazetteer2015.html) a leaflet map was constructed with scaled circles centered at the coordinates given for each county of South Carolina and the size of the circle proportional to the percent voter turnout for the 2016 General Election.
counties<-read.table("2015_Gaz_counties_national.txt", header=TRUE, fill=TRUE, row.names=NULL)
SC_counties<-counties[counties$row.names=="SC",]
SC_votes<-read_html("https://www.scvotes.org/cgi-bin/scsec/vothist?election=vhgen16®vote=VOT")
table<-html_nodes(SC_votes, "table")
SC_votetable<-html_table(table)
SC_counties$ANSICODE<-as.character(SC_counties$ANSICODE)
SC_counties$ANSICODE<-toupper(SC_counties$ANSICODE)
SC_data<-merge(SC_counties[,c(4, 10, 11)], SC_votetable[[2]], by.x="ANSICODE", by.y="X1")
names(SC_data)<-c("County", "lat", "lng", as.character(SC_votetable[[2]][1, 2:13]))
SC_data$'Percent Voting'<-as.numeric(SC_data$'Percent Voting')
SC_data %>%
leaflet() %>%
addTiles() %>%
addCircles(weight=1, radius=sqrt(SC_data$'Percent Voting')*2000)
## Assuming 'lng' and 'lat' are longitude and latitude, respectively