Use shadow matrices and nabular format
mainA shadow matrix is a tidy data structure for missing data that has the same dimensions as your original data. It consists of binary indicators where NA represents a missing value and !NA represents a present value. Variable names in the shadow matrix are suffixed with _NA (e.g., Ozone_NA).
Nabular format is a portmanteau of NA and tabular. It is created by binding the shadow matrix to your original data using bind_shadow() or nabular(). This format is useful for visualisations where you want to split or color data by missingness.
# Create a shadow matrix
as_shadow(airquality)
# Create a nabular data frame (original data + shadow matrix)
bind_shadow(airquality)
# OR
nabular(airquality)
# Example: Using nabular format to color a density plot by missingness
airquality %>%
bind_shadow() %>%
ggplot(aes(x = Temp, fill = Ozone_NA)) +
geom_density(alpha = 0.5)