6.2 Mapping SIRs

A first version:

# a base map, tile by default are OSM
l <- leaflet(map) |> addTiles()

pal <- leaflet::colorNumeric(palette = "YlOrRd", domain = map$SIR)

l |>
  # border
  addPolygons(
    color = "grey", weight = 1,
    fillColor = ~ pal(SIR), fillOpacity = 0.5
  ) |>
  # SIR
  addLegend(
    pal = pal, values = ~SIR, opacity = 0.5,
    title = "SIR", position = "bottomright"
  )

Building on it:

  • adding good label:
    • Use stringf()
    • use of htmltools::HTML
labels <- sprintf("<strong> %s </strong> <br/>
  Observed: %s <br/> Expected: %s <br/>
  AFF: %s <br/> SIR: %s",
  map$county, map$Y, round(map$E, 2),
  map$AFF, round(map$SIR, 2)
) |>
  lapply(htmltools::HTML)

Then we add it to our previous codes:

l |>
  addPolygons(
    color = "grey", weight = 1,
    fillColor = ~ pal(SIR), fillOpacity = 0.5,
    highlightOptions = highlightOptions(weight = 4),
    ## here
    label = labels,
    labelOptions = labelOptions(
      style = list(
        "font-weight" = "normal",
        padding = "3px 8px"
      ),
      textsize = "15px", direction = "auto"
    )
  ) |>
  addLegend(
    pal = pal, values = ~SIR, opacity = 0.5,
    title = "SIR", position = "bottomright"
  )

SIR can be problematic if we have low population -> Modeling!