plot_time_mean: Plot time curve of average EEG signal with confidence...

View source: R/compute_mean.R

plot_time_meanR Documentation

Plot time curve of average EEG signal with confidence interval

Description

Plot a time curve of the average EEG signal amplitude together with pointwise confidence intervals (CIs).

Usage

plot_time_mean(
  data,
  FS = 250,
  t0 = 1,
  color = "red",
  fill = "lightsalmon",
  transp = 0.4,
  y_limits = NULL,
  label_0ms = "stimulus",
  label_offset = c(0, 0)
)

Arguments

data

A data frame, tibble or a database table with input data to plot. It should be an output from compute_mean function or an object with the same structure, containing columns: time with labels of time points and average, ci_low, ci_up with values of average signal and lower and upper CI bounds.

FS

The sampling frequency. Default value is 250 Hz.

t0

Index of the zero time point, i.e. point, where 0 ms should be marked (most often time of the stimulus or time of the response).

color

The color of line. Default value is red. The argument accepts standard R color names or hex codes.

fill

The color of CI bound, default value is lightsalmon. The argument accepts standard R color names or hex codes.

transp

A numeric value between 0 and 1 controlling the transparency of the confidence ribbon (corresponding to alpha parameter in geom_ribbon function).

y_limits

A numeric vector of length two, specifying the minimum and maximum y-axis limits. Defaults to NULLfor plot limits determined according to input data.

label_0ms

Character string for the annotation label at the 0ms mark. Default is "stimulus".

label_offset

A numeric vector of length two to offset the stimulus label. The first value indicates a horizontal shift, the second a vertical one. Default is c(0,0) for no shift.

Details

The output in the form of a ggplot object allows to easily edit the result image properties. For interactive version of plot see interactive_waveforms function.

Value

A ggplot object showing the time course of the average EEG signal with pointwise confidence intervals for chosen sensor.

Examples

# Plot average signal with CI bounds for subject 2 from the sensor E65
# excluding outlier epochs 14 and 15

# a) preparing data
# a1) extract required data
edata <- epochdata |>
dplyr::filter(subject == 2 & sensor == "E65" & epoch %in% 1:13)
# a2) baseline correction
data_base <- baseline_correction(edata, baseline_range = 1:10)
# a3) average computing
data_mean <- compute_mean(data_base, amplitude = "signal_base", subject = 2, channel = "E65",
 type = "point")
# b) plotting the average line with default settings
plot_time_mean(data = data_mean, t0 = 10)

diegr documentation built on Nov. 5, 2025, 5:25 p.m.