Skip to contents

Plot one or multiple 1D ¹H NMR spectra using different rendering backends.

Usage

plot_spec(
  x,
  ppm = NULL,
  shift = c(0, 10),
  backend = c("plotly", "base", "ggplot2"),
  add = FALSE,
  ...
)

spec(...)

matspec(...)

Arguments

x

Numeric vector (single spectrum) or numeric matrix (spectra in rows).

ppm

Numeric vector of chemical shift values. Must match ncol(x).

shift

Numeric vector of length 2. Chemical shift window to display (e.g., c(0, 10)).

backend

Character. Rendering backend. One of "plotly", "base", or "ggplot". Defaults to "plotly".

add

Logical. If TRUE and backend = "base", add spectra to an existing plot.

...

Additional arguments passed to the selected backend.

Value

  • "plotly": a plotly object.

  • "ggplot": a ggplot2 object.

  • "base": NULL (invisibly).

Details

The function accepts both single spectra and matrices of spectra. Input is internally normalized to matrix form, subset to the selected ppm region, and then rendered using the chosen backend.

For large NMR datasets (e.g., >500 spectra × >10k ppm), the "base" and "plotly" backends are substantially more memory-efficient than "ggplot", which requires reshaping to long format.

Chemical shift axes are automatically displayed in decreasing order (NMR convention).

Examples

data(hiit_raw)
plot_spec(hiit_raw)
plot_spec(hiit_raw, shift=c(-0.05,0.05), backend='base') plot_spec(hiit_raw, shift=c(-0.05,0.05), backend='ggplot2')