plotspc {hyperSpec}R Documentation

Plotting Spectra

Description

Plot the spectra of a hyperSpec object, i.e. intensity over wavelength. Instead of the intensity values of the spectra matrix summary values calculated from these may be used.

Usage

plotspc(object, wl.range = NULL, wl.index = FALSE,
        wl.reverse = FALSE,
        spc.nmax = 50, func = NULL, func.args = list(), stacked = NULL, 
        add = FALSE, bty = "l", col = "black", plot.args = list (),
        xoffset = 0, yoffset = 0, nxticks = 10, axis.args = list (),
        fill = NULL, fill.col = NULL, border = NA, title.args = list(),
        polygon.args = list(), lines.args = list(), 
        zeroline = list (lty = 2, col = col))

Arguments

object the hyperSpec object
wl.range the wavelength range to be plotted.
Either a numeric vector or a list of vectors with different wavelength ranges to be plotted separately.
The values can be either wavelengths or wavelength indices (according to wl.index).
wl.index if TRUE, wl.range is considered to give column indices into the spectra matrix. Defaults to specifying wavelength values rather than indices.
wl.reverse if TRUE, the wavelength axis is plotted backwards.
spc.nmax maximal number of spectra to be plotted (to avoid accidentally plotting of large numbers of spectra).
func a function to apply to each wavelength in order to calculate summary spectra such as mean, min, max, etc.
func.args list with furter arguments for func
add if TRUE, the output is added to the existing plot
bty see par
col see par. col might be a vector giving individual colors for the spectra.
plot.args list with further arguments to plot
xoffset vector with abscissa offsets for each of the wl.ranges. If it has one element less than there are wl.ranges, 0 is padded at the beginning.
The values are interpreted as the distance along the wavelength axis that the following parts of the spectra are shifted towards the origin. E.g. if wl.range = list (600 \~ 1800, 2800 \~ 3200), xoffset = c(0, 750) xoffset = 750 would result in a reasonable plot. See also the examples.
yoffset ordinate offset values for the spectra.
nxticks hint how many tick marks the abscissa should have.
stacked if not NULL, a "stacked" plot is produced, see the example. stacked may be TRUE to stack single spectra. A numeric or factor is interpreted as giving the grouping, character is interpreted as the name of the extra data column that holds the groups.
axis.args list with further arguments for axis. axis.args$x should contain arguments for plotting the abscissa, axis.args$y those for the ordinate (again as lists).
fill if not NULL, the area between the specified spectra is filled with color col. The grouping can be given as factor or numeric, or as a character with the name of the extra data column to use. If a group contains more than 2 spectra, the first and the last are used.
If TRUE spectra n and nrow (spc) - n build a group.
fill.col character vector with fill color. Defaults to brightened colors from col.
border character vector with border color. You will need to set the line color col to NA in order see the effect.
title.args list with further arguments to title.
title.args may consits of up to 4 lists, title.args$main, $sub, $xlab, and $ylab for which the other parameters then are given individually.
lines.args list with further arguments to lines.
lines.args$type defaults to "l".
polygon.args list with further arguments to polygon which draws the filled areas.
zeroline NULL or a list with arguments abline, used to plot line (s) marking I = 0.
NULL suppresses plotting of the line. The line is by default turned off if yoffset is not 0.

Details

This is hyperSpec's main plotting function for spectra plots.

New plots are created by plot, but the abscissa and ordinate are drawn separately by axis. Also, title is called explicitly to set up titles and axis labels. This allows a huge freedom in customization of the plots.

Value

plotspc invisibly returns a list with

x the abscissa coordinates of the plotted spectral data points
y a matrix the ordinate coordinates of the plotted spectral data points
wavelengths the wavelengths of the plotted spectral data points


This can be used together with spc.identify.

Author(s)

C. Beleites

See Also

plot, axis, title, lines, polygon, par for the description of the respective arguments.

See plot for some predefined spectra plots such as mean spectrum +/- one standard deviation and the like.

identify and locator about interaction with plots.

Examples

plotspc (flu)

## artificial example to show wavelength axis cutting
plotspc (chondro [sample (nrow (chondro), 50)],
         wl.range = list (600 ~ 650, 1000 ~ 1100, 1600 ~ 1700),
         xoffset = c (0, 300, 450))

plotspc (chondro [sample (nrow (chondro), 50)],
         wl.range = list (600 ~ 650, 1000 ~ 1100, 1600 ~ 1700),
         xoffset = c (300, 450))

## some journals publish Raman spectra backwards
plotspc (chondro [sample (nrow (chondro), 50)], wl.reverse = TRUE)

plotspc (laser[(0:4)*20+1,,], stacked = TRUE)

plotspc (laser, func = mean_pm_sd, 
         col = c(NA, "red", "black"), lines.args = list (lwd = 2),
         fill = c (1, NA, 1), 
         fill.col = "yellow", border = "blue",
         polygon.args = list (lty = 2, lwd = 4),
         title.args = list (xlab = expression (lambda[emission] / nm),
                            ylab = list(line = 3.4)),
         axis.args = list (x = list (col = "magenta"), y = list (las = 1))
        )
        
groups <- rep (1 : 3, length.out = nrow (chondro))
mean.pm.sd <- aggregate (chondro, groups, mean_pm_sd)
plot (mean.pm.sd, col = matlab.palette (3), fill = ".aggregate", stacked = ".aggregate")

[Package hyperSpec version 0.95 Index]