Dataset
2017 U.S. Gazetteer Files from US Census Bureau.
download location http://www2.census.gov/geo/docs/maps-data/data/gazetteer/2017_Gazetteer/2017_Gaz_counties_national.zip
data <- as.data.frame(read.table("~/Learning/Data_Science/Developing_Data_Products/2017_Gaz_counties_NC.txt", header = TRUE))
water<- data$AWATER_SQMI > mean(data$AWATER_SQMI)
data$water[water] = "green"
data$water[!water] = "red"
dim(data)
## [1] 100 11
head(data)
## USPS GEOID ANSICODE NAME ALAND AWATER ALAND_SQMI
## 1 NC 37001 1008531 Alamance_County 1096654286 28025249 423.421
## 2 NC 37003 1008532 Alexander_County 673358173 9445986 259.985
## 3 NC 37005 1008533 Alleghany_County 607101004 3715040 234.403
## 4 NC 37007 1008534 Anson_County 1376469217 14612134 531.458
## 5 NC 37009 1008535 Ashe_County 1100901784 8093124 425.061
## 6 NC 37011 1008536 Avery_County 640601890 445285 247.338
## AWATER_SQMI INTPTLAT INTPTLONG water
## 1 10.821 36.04395 -79.40057 red
## 2 3.647 35.92095 -81.17747 red
## 3 1.434 36.48936 -81.13230 red
## 4 5.642 34.97500 -80.10996 red
## 5 3.125 36.44347 -81.49933 red
## 6 0.172 36.07209 -81.92029 red
library(leaflet)
data %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(~INTPTLONG, ~INTPTLAT,
popup = ~NAME,
label = ~as.character(GEOID),
color = data$water) %>%
addLegend(labels = c("Water Area (square miles) < mean", "Water Area (square miles) > mean"), colors = c("red", "green"))