Animated map of arbovirus cases by locality and epidemiological week.

mp_animated_loc(
  path,
  snv_dataset = c("DENV", "ZIKV", "CHIKV"),
  year = NULL,
  week = NULL,
  var = "probable",
  multi = c("sum", "facet"),
  ncol = NA,
  country = TRUE,
  cve_edo = NULL,
  breaks = NULL,
  pal = "-viridis",
  text_size = 0.4,
  fps = 2,
  save = FALSE,
  name = NULL,
  dir = "./",
  width = NULL,
  height = NULL,
  size_range = c(2.5, 14),
  strip_size = 18,
  curve = TRUE,
  map_legend = TRUE,
  legend_title = "Casos por localidad"
)

Arguments

path

path to the SINAVE txt file (e.g. `"DENGUE2_.txt"`, `"ZIKA2_.txt"` or `"CHIKUNGUNYA2_.txt"`).

snv_dataset

arbovirus of the dataset: `"DENV"` (dengue), `"ZIKV"` (Zika) or `"CHIKV"` (chikungunya).

year

year of the dataset (ANO column). If NULL (default), the most recent year in the dataset is used.

week

epidemiological weeks to animate (SEM column), e.g. `1:52`. If NULL (default), all weeks are used.

var

one or more types of cases to map: `"probable"` (probable + confirmed, default), `"confirmado"` (confirmed). Only for `snv_dataset = "DENV"`: `"DNG"` (non-severe dengue), `"DCSA"` (dengue with warning signs), `"DG"` (severe dengue), `"DENV1"`, `"DENV2"`, `"DENV3"` or `"DENV4"` (serotype, RT-PCR triplex). With more than one value, `multi` defines how they are combined.

multi

how to combine several values of `var`: `"sum"` (default) counts together the cases of any of them in one map (e.g. `var = c("DCSA", "DG")`); `"facet"` draws one panel per value in every frame (e.g. `var = c("DENV1", "DENV2", "DENV3", "DENV4")`).

ncol

number of columns of panels when `multi = "facet"` (default NA, automatic).

country

logical. TRUE (default) = whole country with state boundaries; FALSE = the state given in `cve_edo` with municipal boundaries.

cve_edo

INEGI state code ("20" or 20). Required if `country = FALSE`.

breaks

numeric, step between the breaks of the legend and of the colour and size scales (e.g. `breaks = 5` gives 1, 6, 11, ...). If NULL (default), 5 integer breaks from 1 to the maximum number of cases are used (e.g. 1, 6, 12, 18, 23). With `"quantile"`, the quartiles of the cases by locality and week are used (minimum, Q1, median, Q3 and maximum); repeated values are dropped, so there may be fewer than 5 breaks when most localities have 1 or 2 cases.

pal

colour palette of the bubbles (default `"-viridis"`; the minus sign reverses it so that more cases are darker).

text_size

size of the number of cases inside the bubbles (default 0.4; use 0 to hide it).

fps

frames (weeks) per second (default 2).

save

logical. If TRUE the gif is saved in `dir`; if FALSE (default) the animation is only shown.

name

name of the gif file (without extension); `"_loc_animated_map.gif"` is added at the end.

dir

directory where the gif is saved (with "/" at the end).

width, height

size of the gif in pixels. `height` defaults to 2000 (1600 without the curve); `width` is computed from the number of panels, `ncol` and the shape of the map, so the curve has the same width as the maps.

size_range

minimum and maximum size of the bubbles (default `c(2.5, 14)`).

strip_size

text size of the panel titles (default 18). Each title shows the category and its cases of the week.

curve

logical. Add below the maps a line chart of the weekly cases of each category, with the current week marked (default TRUE).

map_legend

logical. Show the legend of the bubbles (size and colour by number of cases) below the maps (default TRUE).

legend_title

title of the bubble legend (default `"Casos por localidad"`).

Value

a gif file of animation (with `multi = "facet"`, the path of the gif, invisibly).

Details

Reads the SINAVE dataset (same processing as [cases_by_loc()]), counts the cases by locality and epidemiological week and builds an animated map (one frame per week) following the workflow of [mp_animated()]. For the whole country the state boundaries are drawn; for a state, its municipal boundaries.

Only probable and confirmed cases (`ESTATUS_CASO` 1 and 2) are used, counted by locality of report (`CVE_EDO_REP` + `CVE_MPO_REP` + `CVE_LOC_REP`) and joined to the INEGI 2020 localities (`rgeomex::iter_2020_loc`). Colour and size scales are the same in every frame and in every panel, so they can be compared. With `multi = "facet"`, a case can appear in more than one panel (e.g. a confirmed DENV2 case in `"confirmado"` and in `"DENV2"`). Each frame is a ggplot2 figure (one panel per value of `var` with `multi = "facet"`, or a single panel) with the week in the title, and the frames are joined with gifski; the gif is shown in the RStudio Viewer (and saved in `dir` if `save = TRUE`). Saving the gif needs the gifski package.

See also

[mp_animated()], [cases_by_loc()]

Author

Felipe Antonio Dzul Manzanilla felipe.dzul.m@gmail.com

Examples

if (FALSE) { # \dontrun{
# whole country, with state boundaries
mp_animated_loc(path = "DENGUE2_.txt", snv_dataset = "DENV",
                year = 2026, week = 1:52,
                save = TRUE, name = "dengue_mexico_2026", dir = "./")

# Oaxaca, confirmed cases, with municipal boundaries
mp_animated_loc(path = "DENGUE2_.txt", snv_dataset = "DENV",
                year = 2026, week = 1:52, var = "confirmado",
                country = FALSE, cve_edo = "20",
                save = TRUE, name = "dengue_oaxaca_2026", dir = "./")

# severe forms together (DCSA + DG) in one map
mp_animated_loc(path = "DENGUE2_.txt", snv_dataset = "DENV",
                year = 2026, week = 1:52,
                var = c("DCSA", "DG"), multi = "sum",
                save = TRUE, name = "dcsa_dg_mexico_2026", dir = "./")

# one panel per serotype
mp_animated_loc(path = "DENGUE2_.txt", snv_dataset = "DENV",
                year = 2026, week = 1:52,
                var = c("DENV1", "DENV2", "DENV3", "DENV4"),
                multi = "facet", ncol = 2,
                save = TRUE, name = "serotipos_mexico_2026", dir = "./")
} # }