NCBI <- read.csv("~/covidmaps/NCBI.csv")

NCBI <- dplyr::select(NCBI, Accession, U.S._State, Collection_Date)
names(NCBI)[2] <- "state_abv"
NCBI_states <- NCBI %>% group_by(state_abv) %>% 
  count()



cases <- read.csv("~/covidmaps/25April2020_perstate.csv")

cases <- left_join(cases, NCBI_states, by = "state_abv")
## Warning: Column `state_abv` joining factors with different levels, coercing
## to character vector
names(cases)[1] <- "NAME"



states <- rgdal::readOGR("C:/Users/Andrew/Downloads/cb_2018_us_state_5m/cb_2018_us_state_5m.shp", layer = "cb_2018_us_state_5m", GDAL1_integer64_policy = TRUE)
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\Andrew\Downloads\cb_2018_us_state_5m\cb_2018_us_state_5m.shp", layer: "cb_2018_us_state_5m"
## with 56 features
## It has 9 fields
## Integer64 fields read as doubles:  ALAND AWATER
states <- merge(states, cases, by = 'NAME')

bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)

labels <- sprintf(
  "<strong>%s</strong><br/>%g seq. cases </sup>",
  states$NAME, states$n
) %>% lapply(htmltools::HTML)

leaflet(states) %>% 
  addProviderTiles(providers$OpenStreetMap) %>% 
  addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
    opacity = 1.0, fillOpacity = 0.7,
    fillColor = ~colorBin("YlOrRd", domain = n, bins = bins)(n),
    highlightOptions = highlightOptions(color = "white", weight = 2,
      bringToFront = TRUE),
    label = labels,
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px"),
      textsize = "15px",
      direction = "auto")
    ) %>% 
  setView(lng = -95, lat = 40, zoom = 3.5) %>% 
  addLegend(pal = colorBin("YlOrRd", domain = n, bins = bins), values = ~density, opacity = 0.7, title = NULL,
  position = "bottomright")
## Warning in is.na(values): is.na() applied to non-(list or vector) of type
## 'closure'