Learn R Programming

SpecHelpers (version 0.1.19)

plotNMRspec: Create and Plot an NMR Spectrum

Description

This function simulates simple NMR spectra. Only 1st order coupling can be handled -- there is currently no capacity for doublet of doublets and other such peaks. The field strength of the "instrument" is taken into account.

Usage

plotNMRspec(peaks, x.range = c(12, 0), MHz = 300, ppHz = 1,
  nuclei = "1H", pkLabs = TRUE, lab.pos = NULL, plot = TRUE, ...)

Arguments

peaks
A data frame with the following columns: delta, mult (multiplicity), J, area, pw. Multiplicity should be given by a number, so use 2 for a doublet. J is in Hz (use 0 for singlets). pw is the peak width at half-height in Hz.
x.range
A numeric vector of length 2 giving the ppm range desired.
MHz
Integer. The operating frequency of the instrument, in MHz.
ppHz
Points per Hz: The number of data points per Hz to use in calculating the spectrum (passed as argument dd to makeSpec). The default (1) works well for 1H NMR spectra. For 13C NMR spectra, where the peaks are very narrow, one may
nuclei
Character. One of c("1H", "13C"). Controls the spacing of the tick marks and labeling of the peaks.
pkLabs
Logical. If TRUE, and nuclei = 1H, the integral is drawn next to the peak. If FALSE, no labels are drawn.
lab.pos
A vector of label positions as along as the number of rows in peaks (the number of peaks in the spectrum). A numeric vector where 2 = left and 4 = right. This adjusts the positions of the labels to be either left or right of the peak as a w
plot
Logical: Shall a plot be made?
...
Other parameters to be passed downstream.

Value

  • Returns a data frame of the type produced by makeSpec. See there for details. x values are in Hz.

See Also

lorentzCurve, makeSpec

Examples

Run this code
### A simulated 1H NMR spectrum

peaks1 <- data.frame(
	delta = c(1.3, 3.75, 3.9, 10.2),
	mult = c(3, 4, 2, 1),
	J = c(14, 14, 14, 0),
	area = c(3, 2, 1, 1),
	pw = c(2, 2, 2, 10))

res <- plotNMRspec(peaks1, x.range = c(12, 0), MHz = 500,
	main = "500 MHz Simulated 1H NMR Spectrum")

### Compare to the same data at 200 MHz and plot together

par(mfrow = c(2,1))
res <- plotNMRspec(peaks1, x.range = c(12, 0), MHz = 500,
	main = "500 MHz Simulated 1H NMR Spectrum")
res <- plotNMRspec(peaks1, x.range = c(12, 0), MHz = 200,
	main = "200 MHz Simulated 1H NMR Spectrum")
par(mfrow = c(1,1))

### Zoom in to show off

par(mfrow = c(2,1))
res <- plotNMRspec(peaks1, x.range = c(4.5, 1), MHz = 500,
	main = "500 MHz Simulated 1H NMR Spectrum")
res <- plotNMRspec(peaks1, x.range = c(4.5, 1), MHz = 200,
	main = "200 MHz Simulated 1H NMR Spectrum")
par(mfrow = c(1,1))

### A simulated 13C NMR spectrum

# This is substantially slower due to the large
# chemical shift range

peaks2 <- data.frame(
	delta = c(160, 155, 145, 143, 135, 60, 32),
	mult = rep(1, 7),
	J = rep(1, 7),
	area = c(0.1, 0.3, 0.3, 1, 1, 0.5, 0.5),
	pw = rep(1, 7))

res <- plotNMRspec(peaks2, x.range = c(180, 0), MHz = 200,
	main = "200 MHz Simulated 13C NMR Spectrum", ppHz = 4,
	pkLabs = FALSE, nuclei = "13C")

# Try repeating the above with ppHz = 1; note the peaks heights are not quite right
# as there are not enough data points to define the peak properly.

Run the code above in your browser using DataLab