The below data and map function downloads data from the U.S. Burea website regarding the population centers of each US state. The population center is the geographic location within each state that describes the geographic centerpoint of the state’s population.
require(leaflet)
require(maps)
url<- "http://www2.census.gov/geo/docs/reference/cenpop2010/CenPop2010_Mean_ST.txt"
download.file(url, destfile=
"./CenPop2010_Mean_ST.txt")
pop.center<-read.delim("./CenPop2010_Mean_ST.txt",sep=",", stringsAsFactors = F )
colnames(pop.center)<-tolower(colnames(pop.center))
state.map<-map("state",fill = T, plot = F)
The map displays blue circles that are centered around each state’s population center and sized according to the state’s actual population. If you click on the circle the pop-up gives you the state’s population.
map1<-leaflet()%>%
addTiles()%>%
addPolygons(data=state.map,
fillColor = topo.colors(10, alpha = NULL),
stroke = FALSE)%>%
addCircles(data=pop.center,
weight=3,
radius=~sqrt(population)*50,
popup= paste(
pop.center$stname, "<br>",
as.character(pop.center$population)))
map1