plot_tilt: Store Plots of RR Series in Folders and Produce RMSSD and...

View source: R/plot_tilt.R

plot_tiltR Documentation

Store Plots of RR Series in Folders and Produce RMSSD and pNN50 Output

Description

Creates plots of heart rate variability data and saves them to specified folders while calculating time domain metrics (RMSSD and pNN50).

Usage

plot_tilt(.data, folder, type)

Arguments

.data

A data frame containing HRV data from previous tidyrhrv functions

folder

A character string specifying the folder name for saved plots

type

A character string indicating whether data are "filtered" or "original"

Value

A list of data frames containing RMSSD and pNN50 values for each dataset

Examples


# This example requires RHRV package for HRV analysis
if (requireNamespace("RHRV", quietly = TRUE)) {
  temp_dir <- tempdir()
  
  # Generate synthetic HRV data
  hrv_data <- data.frame(
    Time = seq(0, 25, by = 0.8),
    niHR = 75 + rnorm(32, 0, 4),
    RR = 60/75 + rnorm(32, 0, 0.08)
  )
  
  write.csv(hrv_data, file.path(temp_dir, "plot_test.csv"), row.names = FALSE)
  
  # Read and prepare data
  raw_data <- read_tilt(temp_dir, read.csv)
  prepped_data <- prep_data(raw_data, "Time", "niHR", "RR")
  
  # Create plots and calculate metrics  
  plot_folder <- "test_hrv_plots"
  results <- plot_tilt(prepped_data, plot_folder, "original")
  
  print("Plots created and metrics calculated")
  
  # Clean up
  unlink(file.path(temp_dir, "plot_test.csv"))
  unlink(plot_folder, recursive = TRUE)
} else {
  message("RHRV package required for this function")
}


tidyrhrv documentation built on Aug. 8, 2025, 6:20 p.m.

Related to plot_tilt in tidyrhrv...