Learn R Programming

tidyrhrv (version 1.1.0)

plot_tilt: 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)

Value

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

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"

Examples

Run this code
# \donttest{
# 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")
}
# }

Run the code above in your browser using DataLab