Visualizing actograms, average activity and diurnality index

Hassan Roland Nasser

2022-07-23

The most three commonly used tools to perform a first inspection on activity data are:

We start by loading a dataset from the library digiRhythm, we then remove the outliers and resample it to 15 min. We choose one activity to study.

library(digiRhythm)
data <- digiRhythm::df691b_1
data <- remove_activity_outliers(data)
data <- resample_dgm(data, 15)
activity = names(data)[2]
head(data)
#>              datetime Motion.Index Steps
#> 1 2020-08-25 00:00:00           20     8
#> 2 2020-08-25 00:15:00           52    46
#> 3 2020-08-25 00:30:00           61    39
#> 4 2020-08-25 00:45:00           29    18
#> 5 2020-08-25 01:00:00           83    26
#> 6 2020-08-25 01:15:00           50    23

Actograms

We then proceed to plot the actogram of the activity. We can choose the start and end date of the actogram. We can also choose an alias for the activity. This alias is used for aesthetics purpose in the plots. For instance, if the name of the activity column is motion.index, we don’t probably want to show this string in the plot’s legend, but rather have it coded properly as ‘Motion Index’. The actogram function also offers the possibility to save then graph directly in a path as shown in the commented line below. Users only provide the path (relative or physical) without the file name ignoring the extension. All pictures in digiRhythm are saved with the tiff format as it’s the most widely used extension for scientific publications.

User have the possibility to save the plot with another extension or configuration simply by saving the actogram object in a variable (which is a ggplot object) and control it as they wish to.

start <- "2020-08-25" #year-month-day
end <- "2020-10-11" #year-month-day -->
activity_alias <- 'Motion Index'
#save <- 'sample_results/actogram' #if NULL, don't save the image
my_actogram <- actogram(data, activity, activity_alias , start, end, save = NULL)

Average Activity

Now, we plot the average activity. We follow the same dataframe and same logic like for the actograms.

start <- "2020-08-25" #year-month-day
end <- "2020-10-11" #year-month-day -->
activity_alias <- 'Motion Index'
#save <- 'sample_results/actogram' #if NULL, don't save the image
my_daa <- daily_average_activity(data, activity, activity_alias , start, end, save = NULL)

Diurnality Index

The diurnality index could be computed and plotted using the diurnality function as follows.

day_time = c("06:30:00", "16:30:00")
night_time = c("18:00:00", "T05:00:00")
my_di <- diurnality(data, activity,day_time, night_time)