plotNMRspec {SpecHelpers} | R Documentation |
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 |
Integer, but numeric works too!
Points per Hz: The number of data points per Hz to use in
calculating the spectrum (passed as argument |
nuclei |
Character. One of |
pkLabs |
Logical. If |
lab.pos |
A vector of label positions as along as the number of rows in
|
plot |
Logical: Shall a plot be made? |
... |
Other parameters to be passed downstream. These may affect
the plot. You can also include |
Value
Returns a data frame of the type produced by makeSpec
.
See there for details. x values are in Hz.
Details
Note that this function uses Hz internally so that the x.range
, which
is in ppm, is multiplied by Mhz
before being sent to
makeSpec
, and once there, makeSpec
will multiply it by
ppHz
. Thus the total data points used is floor(ppHz * Mhz *
abs(diff(x.range)))
. This approach ensures that peaks are not distorted
when changing x.range
for the same peak.list
.
Note that ppHz
can be numeric as well, due to the use of floor
.
This can be useful: if you wanted your simulated NMR spectrum to be composed
of exactly 16384 data points as real data might be, you can call the function
with ppHz
specified like ppHz = 2^14/(12*500)
and it works!
Author(s)
Bryan A. Hanson, DePauw University. hanson@depauw.edu
See Also
Examples
### 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.