4  Time series

library(rtemis.draw)

Attaching package: 'rtemis.draw'
The following object is masked from 'package:graphics':

    Axis

draw_ts() adds rolling summaries to ordered observations. draw_xt() compares series that share a time scale, with an optional second value axis and separate observation times. Numeric, Date, and POSIXct coordinates retain their spacing.

4.1 Raw observations and a rolling summary

The air-quality data record daily measurements in New York from May through September 1973. A seven-observation mean smooths the daily ozone measurements:

air <- datasets::airquality
air[["date"]] <- as.Date(sprintf("1973-%02d-%02d", air[["Month"]], air[["Day"]]))
draw_ts(list(Ozone = air[["Ozone"]]), time = air[["date"]],
        window = 7L, roll_fn = "mean", align = "center",
        ylab = "Ozone (ppb)", zoom = TRUE)

A window counts observations, rather than elapsed days. Here there is one row per day, including days with missing ozone measurements. A window containing a missing value remains missing. The summary and observations share a legend entry, so selecting a series toggles both layers.

4.2 Compare different units

A second value axis lets each measurement retain its units:

draw_xt(air[["date"]], list(Ozone = air[["Ozone"]]),
        y2 = list(Temperature = air[["Temp"]]),
        ylab = "Ozone (ppb)", y2lab = "Temperature (F)", zoom = TRUE)

For observations collected on a different schedule, supply their times in x2 along with y2. Missing values break the raw line; they are not replaced or connected across the gap.

4.3 Save the configuration

The same controls are available through column bindings:

config <- setup_TimeSeriesConfig(x = "date", y = "Ozone", y2 = "Temp",
  ylab = "Ozone (ppb)", y2lab = "Temperature (F)", zoom = TRUE)
draw(config, data = air)

zt and shade_bin bind optional columns containing zeitgeber phase labels and zero/one shading flags. show_zt_every controls label density while retaining phase zero. These use one shared time vector. Shading runs span their first and last observation; an isolated flag has no duration. For known interval endpoints, pass explicit shade_interval pairs to draw_xt().

4.4 Summarize by calendar period

For distributions within time periods, form explicit calendar groups and use the ordinary boxplot API:

draw_boxplot(air[["Ozone"]], group = format(air[["date"]], "%Y-%m"),
             boxpoints = "all", xlab = "Month", ylab = "Ozone (ppb)")
2026-10-02 10:32:35 Removed 37 NA values from data [boxplot_option]
© 2026 E.D. Gennatas