Map the NPAFP rate, SPI, and their classification
Source:R/spi_compare_npafp.R
spi_compare_npafp_maps.RdMaps the NPAFP rate, SPI, and their agreement for one year:
Panel A – conventional NPAFP rate per 100,000 under-15 person-years, grouped into the reporting bands (
<1, 1-2, 2-3, 3-6, 6-12, 12-24, >=24). Values below the selected NPAFP target are drawn on the red end of the palette.Panel B – SPI (the posterior median for the model-based SPI), categorised on breaks approximately symmetric on the log scale around the reference of 1 (default
-Inf, 0.5, 0.75, 1, 1.33, 2, Inf). Bins at or below the SPI threshold are warm; the rest are cool.Panel C – the SPI and NPAFP category of each district (
Neither below,Both below,SPI below threshold only,NPAFP below target only).
The panels are composed via patchwork so the returned object plots
as a single figure but each panel is a full ggplot you can extract
or restyle.
The maps keep their geographic aspect ratio. Choose image dimensions that
match the boundaries to limit empty space. For a wide region, try a 3:1
width-to-height ratio, such as ggsave(width = 15, height = 5). A region
that is taller than it is wide needs a taller image.
Arguments
- comparison
A
spi_compare_npafp()result.$district_yearmust containyear,npafp_rate,spi_median, andcategory.- boundaries
sfobject with the district id column matchingcomparison$id_coland a POLYGON geometry column.- year
Integer. Which year to display. Defaults to the maximum year in the comparison table.
- spi_threshold, npafp_target
Numeric cuts used in the panel subtitles. If NULL (default) they are pulled from
comparison$thresholds.- npafp_breaks, spi_breaks
Numeric break vectors used for the categorical fills. Defaults match the paper.
- id_col
Character. Name of the district id column in
boundaries. Inferred fromcomparison$id_colif NULL.- titles
Optional character vector of length 3 to override the default panel titles.
- year_label
Character. What to call the displayed year in the panel titles. Defaults to the plain year (e.g.
"2023"). Passsprintf("year T-1: %d", year)when displaying this map beside detections from the following year.- provinces
Logical. Add province outlines in dark grey over the district maps. Default
TRUE. The outlines are formed by merging district polygons. If district edges do not align, this can leave small gaps or strips; setFALSEto omit the province outlines.
Examples
if (FALSE) { # \dontrun{
spi_dy <- spi_index(
cases = synth_surveillance$cases,
population = synth_surveillance$population,
adjacency = synth_surveillance$boundaries,
first_assessment = 2018,
id_col = "adm2_guid"
)
comparison <- spi_compare_npafp(
spi = spi_dy,
cases = synth_surveillance$cases,
population = synth_surveillance$population,
boundaries = synth_surveillance$boundaries
)
spi_compare_npafp_maps(
comparison, synth_surveillance$boundaries, year = 2023
)
} # }