Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plotSpectra

Plot Spectra Object


Description

Plots the spectra stored in a Spectra object. One may choose which spectra to plot, and the x range to plot. Spectra may be plotted offset or stacked. The vertical scale is controlled by a combination of several parameters.

Usage

plotSpectra(
  spectra,
  which = c(1),
  yrange = range(spectra$data),
  offset = 0,
  amplify = 1,
  lab.pos = mean(spectra$freq),
  showGrid = TRUE,
  leg.loc = "none",
  ...
)

Arguments

spectra

An object of S3 class Spectra.

which

An integer vector specifying which spectra to plot, and the order.

yrange

A vector giving the limits of the y axis desired, for instance c(0, 15). This parameter depends upon the range of values in the stored spectra and defaults to the height of the largest peak in the data set. Interacts with the next two arguments, as well as the number of spectra to be plotted as given in which. Trial and error is used to adjust all these arguments to produce the desired plot.

offset

A number specifying the vertical offset between spectra if more than one is plotted. Set to 0.0 for a stacked plot.

amplify

A number specifying an amplification factor to be applied to all spectra. Useful for magnifying spectra so small features show up (though large peaks will then be clipped, unless you zoom on the x axis).

lab.pos

A number giving the location for the identifying label. Generally, pick an area that is clear in all spectra plotted. If no label is desired, give lab.pos outside the plotted x range.

showGrid

Logical. Places light gray vertical lines at each tick mark if TRUE.

leg.loc

Character; if "none" no legend will be drawn. Otherwise, any string acceptable to legend.

...

Additional parameters to be passed to plotting functions.

Value

None. Side effect is a plot.

Author(s)

Bryan A. Hanson, DePauw University.

See Also

plotSpectraJS for the interactive version. Additional documentation at https://bryanhanson.github.io/ChemoSpec/

Examples

data(metMUD1)
plotSpectra(metMUD1,
  main = "metMUD1 NMR Data",
  which = c(10, 11), yrange = c(0, 1.5),
  offset = 0.06, amplify = 10, lab.pos = 0.5
)

# Add a legend at x, y coords
plotSpectra(metMUD1,
  main = "metMUD1 NMR Data",
  which = c(10, 11), yrange = c(0, 1.5),
  offset = 0.06, amplify = 10, lab.pos = 0.5,
  leg.loc = list(x = 3.2, y = 1.45)
)

ChemoSpec

Exploratory Chemometrics for Spectroscopy

v5.3.11
GPL-3
Authors
Bryan A. Hanson [aut, cre] (<https://orcid.org/0000-0003-3536-8246>), Mike Bostock [cph, ctb] (author of the d3.js library used by plotSpectraJS, http://d3js.org), Matt Keinsley [ctb] (author of initial AOV-PCA code)
Initial release
2021-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.