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

plotScoresRGL

Interactive 3D Score Plot of a Spectra Object


Description

This function uses the rgl package to create an interactive plot of PCA scores derived from a Spectra object. A title and legend can be added if desired. Classical or robust confidence ellipses may be added if desired.

Usage

plotScoresRGL(
  spectra,
  pca,
  pcs = c(1:3),
  ellipse = TRUE,
  rob = FALSE,
  cl = 0.95,
  frac.pts.used = 0.8,
  title = NULL,
  t.pos = NULL,
  leg.pos = NULL,
  lab.opts = FALSE,
  tol = 0.01,
  use.sym = FALSE,
  axes = "fixed",
  ...
)

Arguments

spectra

An object of S3 class Spectra.

pca

An object of class prcomp.

pcs

A vector of three integers specifying the PCA scores to plot.

ellipse

Logical indicating if confidence ellipses should be drawn.

rob

Logical; if ellipse = TRUE, indicates that robust confidence ellipses should be drawn. If FALSE, classical confidence ellipses are drawn.

cl

A number indicating the confidence interval for the ellipse.

frac.pts.used

If ellipse = TRUE and rob = TRUE, a number indicating the fraction of the data points to be considered "good" and thus used to compute the robust confidence ellipse.

title

A character string for the plot title.

t.pos

A character selection from LETTERS[1:8] ( = A through H) indicating the desired location for the title.

leg.pos

A character selection from LETTERS[1:8] ( = A through H) indicating the desired location for the legend.

lab.opts

A logical indicating whether or not to display the locations where the title and legend can be placed. These locations are the corners of a cube surrounding the data.

tol

Quantile to be used to label extreme data points.

use.sym

logical; if true, the color scheme is changed to black and symbols are used for plotting.

axes

character; One of "fixed" or "float". For "fixed", reference axes are drawn along the positive x, y and z axes. The length of the axes is the maximum of the the data values, so that all data points are inside the reference axes if positive. For "float" the reference axes are drawn along the positive x, y and z axes, but the length of each axis corresponds to maximum for each dimension separately. This option may make better use of the drawing space.

...

Additional parameters to pass downstream, generally to the plotting routines.

Details

If you intend to make a hard copy of your plot, use lab.opts = TRUE until you have found a good view of your data. Then note corners of the cube where the title and legend won't interfere with viewing the data, and use these as arguments for t.pos and leg.pos, and add title. Adjust as necessary, then turn off label display using lab.opts = FALSE. Back at the console, use > rgl.snapshot("file_name.png") to create the hardcopy.

Value

None. Side effect is a plot

Author(s)

Bryan A. Hanson, DePauw University.

See Also

Other functions in ChemoSpec that plot PCA scores are: plotScores (2D version), and plotScores3D (uses lattice graphics). Additional documentation at https://bryanhanson.github.io/ChemoSpec/

Examples

## Not run: 
data(metMUD1)
pca <- c_pcaSpectra(metMUD1, choice = "autoscale")
plotScoresRGL(metMUD1, pca,
  title = "metMUD1 NMR Spectra",
  leg.pos = "A", t.pos = "B"
)

## End(Not run)

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.