Skip to contents

This function generates a plot showing the distribution of gap sizes (consecutive NA values) in the data, either aggregated or broken down by keypoints.

Usage

check_na_gapsize(data, limit = 10, include_total = TRUE, by_keypoint = TRUE)

Arguments

data

A data frame containing at least the columns x and keypoint.

limit

An integer specifying the maximum gap size to include in the plot. Default is 10.

include_total

Logical. If TRUE, includes the total count of gaps of each size in the plot. Default is TRUE.

by_keypoint

Logical. If TRUE, generates a separate plot for each keypoint. If FALSE, creates a single aggregated plot for all keypoints. Default is TRUE.

Value

A patchwork object combining one or more ggplots that visualize the occurrence of gap sizes (consecutive NAs) in the data.

Details

  • The plot highlights the most common gap sizes in the data, ordered by frequency.

  • Different colors represent the occurrence (indianred), total counts (steelblue), and border outlines (black).

  • The function uses patchwork to combine multiple plots when by_keypoint = TRUE.

Examples

library(dplyr)
library(ggplot2)
library(patchwork)
data <- dplyr::tibble(
  x = c(NA, NA, 3, NA, 5, 6, NA, NA, NA, 10),
  keypoint = factor(rep(c("head", "arm"), each = 5))
)
check_na_gapsize(data, limit = 5, include_total = TRUE, by_keypoint = TRUE)