Builds a population pyramid of confirmed dengue cases from the SINAVE dataset, with males on the left, females on the right and the age groups in the centre. Each side is headed by a Font Awesome icon and the total number of cases by sex, which act as the legend.
plt_pyramid(
data,
col_male = "#0072B2",
col_female = "#CC79A7",
gap = 0.18,
size_age = 3.5,
size_count = 3,
icon_male = "person",
icon_female = "person-dress",
show_zero = FALSE,
title = NULL,
subtitle = NULL,
caption = "Fuente: SINAVE/DGE, Secretaría de Salud."
)data.frame with the SINAVE dengue dataset. It must contain the columns `ESTATUS_CASO`, `IDE_SEX`, `IDE_EDA_ANO`, `CVE_EDO_REP` and `CVE_MPO_REP` (names are standardised with [janitor::clean_names()]). Only confirmed cases (`ESTATUS_CASO == 2`) are used.
colour for males (default `"#0072B2"`, Okabe-Ito blue).
colour for females (default `"#CC79A7"`, Okabe-Ito reddish purple).
width of the central space for the age labels, as a proportion of the largest count (default 0.18). Increase it if the labels look crowded.
text size of the age-group labels (default 3.5).
text size of the number of cases (default 3).
names of free Font Awesome icons drawn above each side (default `"person"` and `"person-dress"`; other options are `"mars"`/`"venus"` or `"child"`/`"child-dress"`). See <https://fontawesome.com/search?ic=free>.
logical. If TRUE, age groups without cases are labelled with 0 (default FALSE).
plot title and subtitle (default NULL, none).
plot caption (default cites SINAVE/DGE).
a ggplot object.
Ages are grouped into 15 classes: `<1`, `1-4`, `5-9`, ..., `60-64` and `65+` (intervals are closed on the left). Age groups without cases are kept with a count of 0, so the pyramid never has gaps. The number of cases is printed inside each bar when it fits and outside otherwise. The x axis shows absolute counts on both sides.
Icons are rendered from SVG with fontawesome and rsvg, so no system font is required and they are kept when saving with [ggplot2::ggsave()].
[fontawesome::fa()]
if (FALSE) { # \dontrun{
x <- data.table::fread("DENGUE2_.txt", quote = "", fill = TRUE)
plt_pyramid(data = x,
title = "Casos confirmados de dengue por grupo de edad y sexo",
subtitle = "Jalisco, 2026")
# other colours and icons
plt_pyramid(data = x,
col_male = "#1B9E77", col_female = "#D95F02",
icon_male = "mars", icon_female = "venus",
show_zero = TRUE)
ggplot2::ggsave("pyramid.png", width = 8, height = 7, dpi = 300)
} # }