Package 'ravebuiltins'

Title: Builtin Modules for 'RAVE'
Description: This package provides builtin modules for 'RAVE'. It aims to analyze and visualize 'iEEG' data from different perspectives.
Authors: John Magnotti [cre, aut], Zhengjia Wang [aut]
Maintainer: John Magnotti <[email protected]>
License: MIT + file LICENSE
Version: 1.99.0
Built: 2026-10-15 18:14:26 UTC
Source: https://github.com/beauchamplab/ravebuiltins

Help Index


⁠Welch⁠ periodogram per condition

Description

⁠Welch⁠ periodogram per condition

Usage

by_condition_welch(results, ...)

Arguments

results

results returned by module

...

other parameters passed to module output


By Trial Plot for ⁠ERP⁠ data

Description

By Trial Plot for ⁠ERP⁠ data

Usage

by_trial_erp_map(results, ...)

Arguments

results

results returned by module

...

other parameters passed to module output


Draws an orange, dashed horizontal line at cut. Checks for not null and length > 0

Description

Draws an orange, dashed horizontal line at cut. Checks for not null and length > 0

Usage

draw_cut_point(cut = NULL)

Arguments

cut

the location(s) of the lines

Value

the value of cut (invisibly)


Draw several heatmaps in a row and (optionally) a color bar

Description

Easy way to make a bunch of heatmaps with consistent look/feel and get a color bar. By default it is setup for time/freq, but by swapping labels and decorators you can do anything.

Usage

draw_many_heat_maps(
  hmaps,
  max_zlim = 0,
  percentile_range = FALSE,
  log_scale = FALSE,
  show_color_bar = TRUE,
  useRaster = TRUE,
  wide = FALSE,
  PANEL.FIRST = NULL,
  PANEL.LAST = NULL,
  PANEL.COLOR_BAR = NULL,
  axes = c(TRUE, TRUE),
  plot_time_range = NULL,
  special_case_first_plot = FALSE,
  max_columns = 2,
  decorate_all_plots = FALSE,
  center_multipanel_title = FALSE,
  ignore_time_range = NULL,
  marginal_text_fields = c("Subject ID", "Electrode", "Frequency"),
  extra_plot_parameters = NULL,
  do_layout = TRUE,
  ...
)

Arguments

hmaps

data to draw heatmaps

max_zlim

zlim that trims z value

percentile_range

whether to draw in percentile

log_scale

draw y in log scale?

show_color_bar

show color legend to the right? Future: Will will check to see if this parameter is a function. If so, we can call it to allow arbitrary legends in the right-most (half) panel

useRaster, ...

passed to image()

wide

boolean. should we use a wider margin on the left? defaults to false

PANEL.FIRST

a function that is called after each plot window has been created, but before any rendering is done. In truth, this is currently called AFTER the call to image(), so if you draw within the plotting region it will overwrite the heatmap. To fix this requires editing make_image to allow for a function to be called after creation but before rendering. Don't depend on this call order, use PANEL.LAST if you want to draw things on top of the heatmap

PANEL.LAST

a function that is called after the rendering of each heat map. It is not called after the rendering of the color bar.

PANEL.COLOR_BAR

a function to adjust color bar width

axes

vector of logicals, whether to draw axis

plot_time_range

x range, similar to xlim

special_case_first_plot

logical, whether the first panel gets its own treatment (for example a wider left margin) instead of the shared layout

max_columns

maximum number of heatmap columns before wrapping onto additional rows (default 2)

decorate_all_plots

logical, whether PANEL.FIRST/PANEL.LAST run on every panel rather than only the first

center_multipanel_title

logical, whether a multi-panel title is centered across the whole figure instead of over the first panel

ignore_time_range

optional time range to exclude from the drawn data

marginal_text_fields

character vector naming which fields are written into the plot margin (default Subject ID, Electrode, Frequency)

extra_plot_parameters

optional named list of additional graphical parameters forwarded to the individual heatmap panels

do_layout

logical, whether to call layout_heat_maps to build the panel layout. Set FALSE when the caller manages the layout.

Value

Called for its side effect of drawing the heatmaps; returns NULL invisibly.


Voltage Time Series Plot

Description

Voltage Time Series Plot

Usage

erp_over_time_plot(results, ...)

Arguments

results

results returned by module

...

other parameters passed to module output


Interpolate a heatmap palette to a given number of colors

Description

Expands a short heatmap palette into a smooth color ramp of ncolors entries, suitable for passing to image or to a threeBrain viewer.

Usage

expand_heatmap(pal, results, ncolors = 101, space = "Lab", ...)

Arguments

pal

a character vector of colors, or the name of one of the builtin palettes returned by get_heatmap_palette

results

optional RAVE results object; when supplied, ncolors and the palette name are read from it instead

ncolors

number of colors in the returned ramp (default 101)

space

color space used for interpolation, passed to grDevices::colorRampPalette (default 'Lab')

...

further arguments passed to grDevices::colorRampPalette, for example bias

Value

A character vector of ncolors hex color strings.

See Also

get_heatmap_palette

Examples

expand_heatmap(get_heatmap_palette('BlueWhiteRed'), ncolors = 101)

Builtin diverging heatmap palettes

Description

Returns one of the builtin diverging color palettes used for RAVE heatmaps. Most are adapted from https://colorbrewer2.org. Each palette has an odd number of colors so that the middle entry is the neutral midpoint.

Usage

get_heatmap_palette(pname, get_palettes = FALSE, get_palette_names = FALSE)

Arguments

pname

palette name, one of the values returned by this function with get_palette_names = TRUE. If missing, all palettes are returned. An unrecognized name warns and falls back to a random palette.

get_palettes

ignored, kept for backward compatibility

get_palette_names

whether to return the available palette names instead of a palette; only used when pname is missing

Value

A character vector of hex colors carrying a name attribute; or, when pname is missing, the full named list of palettes, or a character vector of palette names if get_palette_names = TRUE.

See Also

expand_heatmap

Examples

get_heatmap_palette(get_palette_names = TRUE)
get_heatmap_palette('BlueWhiteRed')

Function to get builtin color palettes

Description

Function to get builtin color palettes

Usage

get_palette(pname, get_palettes = FALSE, get_palette_names = FALSE)

Arguments

pname

palette name

get_palettes

ignored

get_palette_names

whether to get palette names


Append the electrode count to each label

Description

Collapses a vector of electrode labels to its unique values and appends the number of electrodes carrying each label, as ⁠Label[n]⁠.

Usage

make_label_with_count(lbl)

Arguments

lbl

character vector of per-electrode labels, with repeats

Value

A character vector of the unique labels with counts appended. The result carries a map attribute giving, for each element of lbl, the index of its label in the returned vector.

See Also

remove_count_from_label

Examples

make_label_with_count(c('G 1', 'G 1', 'S 2'))

Time Series Plot

Description

Time Series Plot

Usage

over_time_plot(results, ...)

Arguments

results

results returned by module

...

other parameters passed to module output


Plot grouped data as points, means and error bars

Description

This doesn't do any decoration, it's designed for use with rutabaga::create_frames. Note that we're using barplot to set the x- and y-range of the plot. Does not handle log axes correctly.

Usage

plot_grouped_data(
  mat,
  yvar,
  xvar,
  gvar = NULL,
  types = c("jitter points", "means", "ebar polygons"),
  layout = c("grouped", "overlay"),
  draw0 = TRUE,
  draw0.col = "black",
  ylim = NULL,
  col = NULL,
  ...,
  plot_options = NULL,
  jitter_seed
)

Arguments

mat

a data.frame or data.table holding the data to plot

yvar

name of the column holding the response values

xvar

name of the column defining positions along the x axis

gvar

name of the grouping column, or NULL for no grouping

types

character vector selecting which layers to draw; any of 'jitter points', 'means' and 'ebar polygons'

layout

whether groups are drawn side by side ('grouped') or on top of one another ('overlay')

draw0

logical, whether to draw a reference line at zero

draw0.col

color of the zero reference line (default black)

ylim

y axis limits; computed from the data when NULL

col

vector of colors, one per group; defaults to the active palette

...

extra options to pass to barplot during plot creation

plot_options

optional named list of graphical parameters such as pch and lwd, overriding the defaults

jitter_seed

optional integer seed making the point jitter reproducible across redraws

Value

Called for its side effect of drawing the plot; returns NULL invisibly.


Draw a plot title that respects the RAVE dark mode

Description

Wraps graphics::title, defaulting the color to the current foreground so titles stay legible when par('bg') is dark, and shrinking the text when the plot is being written to a file.

Usage

rave_title(main, cex = rave_cex.main, col, font = 1, adj = 0.5, ...)

Arguments

main

the title text, passed to graphics::title

cex

the character expansion for the title (default is rave_cex.main)

col

title color; defaults to the current foreground color

font

the font type (default = 1, plain)

adj

horizontal justification, 0 left, 0.5 centered, 1 right

...

further arguments passed to graphics::title

Value

Called for its side effect of drawing the title; returns the value of graphics::title invisibly.

See Also

title


Strip the electrode count from a label

Description

Removes the trailing ⁠[5]⁠ / ⁠[10]⁠ electrode count that make_label_with_count appends to FreeSurfer labels.

Usage

remove_count_from_label(str)

Arguments

str

character vector of labels

Value

The labels with any trailing bracketed count removed.

See Also

make_label_with_count

Examples

remove_count_from_label('G_temp_sup[5]')

Strip anatomical region prefixes from a label

Description

Removes the leading ⁠GS ⁠, ⁠G ⁠ and ⁠S ⁠ ⁠gyrus⁠/⁠sulcus⁠ markers from FreeSurfer anatomical labels.

Usage

remove_gyrus_sulcus_labels(str)

Arguments

str

character vector of labels

Value

The labels with ⁠gyrus⁠/⁠sulcus⁠ prefixes removed.

See Also

remove_hemisphere_labels

Examples

remove_gyrus_sulcus_labels('G temp_sup')

Strip hemisphere prefixes from a label

Description

Removes the leading ⁠L ⁠ / ⁠R ⁠ hemisphere markers so that labels are compared consistently across hemispheres. Kept in one place so every caller strips them the same way.

Usage

remove_hemisphere_labels(str)

Arguments

str

character vector of labels

Value

The labels with hemisphere prefixes removed.

See Also

remove_gyrus_sulcus_labels

Examples

remove_hemisphere_labels('L G_temp_sup')