6.2 Mapping SIRs
A first version:
# a base map, tile by default are OSM
<- leaflet(map) |> addTiles()
l
<- leaflet::colorNumeric(palette = "YlOrRd", domain = map$SIR)
pal
|>
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
- Use
<- sprintf("<strong> %s </strong> <br/>
labels Observed: %s <br/> Expected: %s <br/>
AFF: %s <br/> SIR: %s",
$county, map$Y, round(map$E, 2),
map$AFF, round(map$SIR, 2)
map|>
) 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!