plotSpectra2D {ChemoSpec2D}R Documentation

Plot a Spectra2D Object


Plots a 2D spectrum stored in a Spectra2D object. This is primarily for inspection and for preparation of final plots. If you need to do extensive exploration, you should probably go back to the spectrometer.


  which = 1,
  lvls = NULL,
  cols = NULL,
  showNA = TRUE,
  showGrid = FALSE,



An object of S3 class Spectra2D.


An integer specifying which spectrum to plot. May be a vector.


A numeric vector specifying the levels at which to compute contours. If NULL, values are computed using calcLvls. If argument which gives more than one spectrum to plot, then lvls must be a list of levels of length(which).


A vector of valid color designations. If provided, must be of the the same length as lvls (i.e. each contour is a particular color). If NULL, defaults to using a scheme of up to nine values running from blue (low) to red (high), centered on green (zero). If argument which gives more than one spectrum to plot, then cols must be a list of colors of length(which).


Logical. Should the locations of peaks removed by removePeaks2D be shown? If present, these are shown by a gray line at each frequency.


Logical. If TRUE, show a dotted gray line at each tick mark.


Additional parameters to be passed to the plotting routines.


Side effect is a plot.


One cannot remove frequencies from the interior of a 2D NMR data set and expect to get a meaningful contour plot, because doing so puts unrelated peaks adjacent in the data set. This would lead to contours being drawn that don't exist in the original data set. This function will check for missing frequencies and stops if any are found.


You can view the color scale for the plot via showScale.

Levels & Colors

The number of levels and colors must match, and they are used 1 for 1. If you provide n colors, and no levels, the automatic calculation of levels may return a number of levels other than n, in which case the function will override your colors and assign new colors for the number of levels it computed (with a message). To get exactly what you want, specify both levels and colors in equal numbers. Function inspectLvls can help you choose appropriate levels.

Overlaying Spectra

If you specify more than one spectrum to plot, e.g. which = c(1,2), then arguments lvls and cols must be lists of levels and colors, one list element for each spectrum to be plotted (if specified at all). Two convenience functions exist to make this process easier: LofL and LofC. See the examples.


Bryan A. Hanson, DePauw University.


mylvls <- seq(5, 30, 5)
  which = 7, lvls = mylvls,
  main = "MUD1 Sample 7"

# Invert the screen which makes the colors pop!
op <- par(no.readonly = TRUE)
par(bg = "black", fg = "white", col.axis = "white", col.main = "white")
  which = 7, lvls = mylvls,
  main = "MUD1 Sample 7"

# Overlay multiple spectra:

  which = c(6, 1), lvls = LofL(mylvls, 2),
  cols = LofC(c("red", "black"), 2, length(mylvls), 2),
  main = "MUD1 Sample 1 (red) & Sample 6 (black)\n(4 of 6 peaks overlap)"

[Package ChemoSpec2D version 0.5.0 Index]