This function uses the d3.js JavaScript library by Mike Bostock to plot a Spectra
object interactively. This is most useful for data exploration. For high
quality plots, consider plotSpectra
.
plotSpectraJS(spectra, which = NULL, browser = NULL, minify = TRUE)
None; side effect is an interactive web page. The temporary directory containing the files that drive the web page is written to the console in case you wish to use those files. This directory is deleted when you quit R. If you wish to read the file, don't minify the code, it will be unreadable.
An object of S3 class Spectra()
.
Integer. If not NULL
, specifies by number which spectra to plot.
If greater control is needed, use removeSample
which is more flexible
before calling this function.
Character. Something that will make sense to your OS. Only
necessary if you want to override your system specified browser as
understood by R
. See below for further details.
Logical. Shall the JavaScript be minified? This improves
performance. However, it requires package js
which in turn requires
package V8
. The latter is not available on all platforms. Details
may be available at https://github.com/jeroen/V8
The browser is called by
browseURL
, which
in turn uses options("browser")
. Exactly how this is handled
is OS dependent.
If browser is NULL
, you are using RStudio, and a
viewer is specified, this will be called. You can stop this by with
options(viewer = NULL)
.
On a Mac, the default browser is called
by /bin/sh/open
which in turn looks at which browser you have set in the system settings. You can
override your default with
browser = "/usr/bin/open -a 'Google Chrome'"
for example.
You can check the performance of your browser at peacekeeper.futuremark.com The most relevant score is the rendering category.
Bryan A. Hanson (DePauw University).
The spectral data are incorporated into the web page. Keep in mind that very large
data sets, like NMR spectra with 32K points, will bog down the browser.
In these cases, you may need to limit the number of samples in passed to this function.
See removeSample
or use argument which
.
plotSpectra
for non-interactive plotting. Details
about d3.js
are at https://d3js.org. Additional documentation at
https://bryanhanson.github.io/ChemoSpec/
if (interactive()) {
require("jsonlite")
require("js")
data(metMUD2)
plotSpectraJS(metMUD2)
}
Run the code above in your browser using DataLab