Context
The contact-matrices episode explains symmetric contact matrices but currently lacks a visual comparison that makes the symmetry argument concrete.
The script 73-socialmixr-ggplot.R in epicatador has two helper functions (format_big_mark, matrix_to_ggplot) that produce ggplot heatmaps of the contact matrix.
Plan
Add a single chunk (on a new branch) that:
- Defines
format_big_mark() — formats tile labels as human-readable numbers (K/M).
- Defines
matrix_to_ggplot() — converts a contact matrix to a geom_tile heatmap using colorspace::scale_fill_continuous_sequential(palette = "OrYel").
- Produces two plots side by side or sequentially:
- Plot 1:
contacts_byage$matrix — mean contacts (asymmetric rates).
- Plot 2:
contacts_byage$matrix * contacts_byage$demography$population — total contacts (symmetric).
The contrast between the two plots makes the symmetry argument visual and explicit.
Adaptations from source
- Uses standard
contacts_byage object (already loaded upstream via contactsurveys pattern).
- Uses
|> instead of %>%.
- Explicit
pkg:: namespacing.
- No
socialmixr::get_survey() — survey loaded upstream.
Dependencies
colorspace (for scale_fill_continuous_sequential)
scales (for label_number)
ggplot2, dplyr (already used in the episode)
Context
The
contact-matricesepisode explains symmetric contact matrices but currently lacks a visual comparison that makes the symmetry argument concrete.The script
73-socialmixr-ggplot.Rinepicatadorhas two helper functions (format_big_mark,matrix_to_ggplot) that produce ggplot heatmaps of the contact matrix.Plan
Add a single chunk (on a new branch) that:
format_big_mark()— formats tile labels as human-readable numbers (K/M).matrix_to_ggplot()— converts a contact matrix to ageom_tileheatmap usingcolorspace::scale_fill_continuous_sequential(palette = "OrYel").contacts_byage$matrix— mean contacts (asymmetric rates).contacts_byage$matrix * contacts_byage$demography$population— total contacts (symmetric).The contrast between the two plots makes the symmetry argument visual and explicit.
Adaptations from source
contacts_byageobject (already loaded upstream viacontactsurveyspattern).|>instead of%>%.pkg::namespacing.socialmixr::get_survey()— survey loaded upstream.Dependencies
colorspace(forscale_fill_continuous_sequential)scales(forlabel_number)ggplot2,dplyr(already used in the episode)