teste = alertas$subtype

lookup = c(
  "HAZARD_ON_ROAD_POT_HOLE" = "Buraco na via",
  "JAM_STAND_STILL_TRAFFIC" = "Trafego ainda fluindo",
  "ROAD_CLOSED EVENT" = "Evento Bloqueando a via",
  "JAM_MODERATE_TRAFFIC" = "Congestionamento moderado",
  "JAM_HEAVY_TRAFFIC" = "Congestionamento pesado",
  "HAZARD_ON_ROAD_CONSTRUCTION" = "Obras na via",
  "HAZARD_ON_ROAD_CAR_STOPPED" = "Carro parado na via",
  "HAZARD_WEATHER_FOG" = "Risco climático",
  "HAZARD_ON_SHOULDER_MISSING_SIGN" = "HAZARD ON SHOULDER MISSING SIGN",
  "ACCIDENT_MAJOR" = "Acidente",
  "ACCIDENT_MINOR" = "Acidente leve"
)

alertas$subtype = lookup[teste]
alertas$type = as.factor(alertas$subtype)
alertas$tipo = as.integer(as.factor(alertas$subtype))
table(alertas$tipo)
## 
##   1   2   3   4   5   6   7   8   9 
##   2 196   3   7  22   3   7   1  13
table(alertas$subtype)
## 
##                        Acidente                   Buraco na via 
##                               2                             196 
##             Carro parado na via       Congestionamento moderado 
##                               3                               7 
##         Congestionamento pesado HAZARD ON SHOULDER MISSING SIGN 
##                              22                               3 
##                    Obras na via                 Risco climático 
##                               7                               1 
##           Trafego ainda fluindo 
##                              13
table(alertas$tipo)
## 
##   1   2   3   4   5   6   7   8   9 
##   2 196   3   7  22   3   7   1  13
df = tibble(
  lat = alertas$location$y,
  lng = alertas$location$x,
  color = alertas$tipo
)
addJS <- 
  pluginFactory(
    "Some JS Plugin", 
    system.file("js", "", package = "leaflethex"), "hexbin.js", "deps.js")

pal <- colorFactor(
  palette = 'Accent',
  domain = df$color
)
leaflet(df, width = 910) %>% 
  addTiles() %>% 
  addCircles(color =~pal(color), stroke = TRUE, radius = 50, weight = 1, fillOpacity = 1) %>%
  addJS(radius = 20, highEndColor = "green")
leaflet(df, width = 910) %>% 
  addTiles() %>% 
  addCircles(color =~pal(color), stroke = TRUE, radius = 50, weight = 1, fillOpacity = 1) %>%
  addJS(radius = 20, highEndColor = "red") 
leaflet(df, width = 910) %>%
  addTiles %>%
  addCircles(color =~pal(color), stroke = TRUE, radius = 50, weight = 1, fillOpacity = 1) %>%
  addHexbin(
    radius = 19,
    lowEndColor = "yellow",

    highEndColor = "purple"
  )
df1 = tibble(
  lat = alertas$location$y,
  lng = alertas$location$x,
  #size = runif(322, 1, 1),
  color = alertas$subtype,
  subtype = alertas$subtype,
  magvar = alertas$magvar,
  reliability = alertas$reliability,
  confidence = alertas$confidence,
  reportRating = alertas$reportRating
)
head(df1)
pal <- colorFactor(
  palette = 'Paired',
  domain = df1$color
)

leaflet(df1, width = 910) %>%
  addTiles(group = "Mapa") %>%
  addCircles(group = "Pontos" ,color =~pal(color), stroke = TRUE, radius = 50, weight = 1, fillOpacity = 1, popup =~paste("Tipo: ", subtype, "<br>Direção°", magvar,"<br>Confiabilidade", reliability, "<br>Confança", confidence, "<br>ReportRating", reportRating, sep = " ")) %>%
  addHexbin(
    radius = 19,
    uniformSize = TRUE,
    lowEndColor = "yellow",
    highEndColor = "red",
    sizeSummaryFunction = "count",
    sizevar = NULL,
    colorSummaryFunction = "count",
    colorvar = NULL
  ) %>%
  addLegend(pal = pal, values = ~color, group = "circles", position = "bottomleft", title = "Ocorrências")

. .. … …. …..