--- title: "Specialty Crop Block Grant Project Numbers by State" author: "ELRC" date: "March 9, 2018" output: html_document --- ```{r setvariable, echo=FALSE, warning=FALSE, message=FALSE} library(leaflet) library(geojson) library(geojsonio) library(sp) setwd("~/R/USDA") states3 <- read.csv("./state.csv") states <- geojson_read("tempgeo.json", what = "sp") bins <- c(0,5,10,15,20,25,30,35,Inf) statesA <- merge(states, states3, by.x="name", by.y="Abbr") pal <- colorBin("YlOrRd", domain = statesA$Projects, bins = bins) r_colors <- rgb(t(col2rgb(colors()) / 255)) names(r_colors) <- colors() ## creating state labels labels <- sprintf( "%s
%g Projects", statesA$name, statesA$Projects ) %>% lapply(htmltools::HTML) ``` Hint: Hover over states to see interactivity. ```{r createmap, echo=FALSE, warning=FALSE} m <- leaflet(statesA) %>% setView(-96, 37.8, 4) %>% addTiles() %>% addPolygons( fillColor = ~pal(Projects), weight = 2, opacity = 1, color = "white", dashArray = "3", fillOpacity = 0.7, highlight = highlightOptions( weight = 5, color = "#666", dashArray = "", fillOpacity = 0.7, bringToFront = TRUE), label = labels, labelOptions = labelOptions( style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "15px", direction = "auto")) ## adding legend m %>% addLegend(pal = pal, values = ~Projects, opacity = 0.7, title = "2013 # of Projects", position = "bottomright") ```