#tidyed project data
GlobalWater <- read.csv("GlobalWatertidy.csv")

#Access geospatial data and save
world <- st_as_sf(map('world', plot = FALSE, fill = TRUE))

#filter project data by the year 2000
GlobalWater2000 <- GlobalWater %>% filter(Year == "2000")

#Combine spatial data and data frame into a single object
Water2000 <- merge(world, GlobalWater2000, by.x="ID", by.y="Country")
#set color plette and html labels
bins <- c(0, 25, 50, 70, 90, 100)
pal <- colorBin(c("#ff540a","#ff910a","#ffce0a","#0aceff","#0759AB"), domain = Water2000$Percent_National, bins = bins)

labels <- sprintf(
  "<strong>%s</strong><br/> %s&#37 Access",
  Water2000$ID, comma(Water2000$Percent_National)) %>% 
  lapply(HTML)

#plot with leaflet
leaflet(Water2000) %>%
  addProviderTiles("Stamen.TonerLite") %>%
  addPolygons(
    fillColor = ~pal(Percent_National),
    fillOpacity = 0.8,
    dashArray = "3",
    weight = 2,
    color = "white",
    opacity = 1,
    highlight = highlightOptions(
      weight = 3,
      color = "#0a0a0a",
      dashArray = "",
      fillOpacity = 0.6,
      bringToFront = TRUE),
    label = labels,
    labelOptions = labelOptions(
    style = list("font-weight" = "normal", padding = "3px 8px"),
    textsize = "15px",
    direction = "auto")) %>%
  addLegend(pal = pal, values = ~Percent_National, opacity = 0.7, title = HTML("% Access to Clean <br> Drinking Water"),
    position = "bottomright")