plotsp: Plotting spectra

View source: R/plotsp.R

plotspR Documentation

Plotting spectra

Description

plotsp plots lines corresponding to the spectra (or more generally row observations) of a data set.

plotsp1 plots only one row observation per plot (i.e. spectrum by spectrum) by scrolling the rows. After running a plotsp1 command, the plots are printed successively by pushing the R console "entry button", and stopped by entering any character in the R console.

Usage


plotsp(X,
  type = "l", col = NULL, zeroes = FALSE, labels = FALSE, 
  blocks = NULL, add = FALSE,
  ...)

plotsp1(X, col = NULL, zeroes = FALSE, ...)

Arguments

X

A n x p matrix or data frame of observations (usually spectra).

type

1-character string giving the type of plot desired. Default value to "l" (lines). See plot.default for other options.

col

A color, or a vector of colors (of length n), defining the color(s) of the lines representing the rows.

zeroes

Logical indicationg if an horizontal line is drawn at coordonates (0, 0) (Default to FALSE).

labels

Logical indicating if the row names of X are plotted (default to FALSE).

blocks

A list whose each component gives the column numbers in X defining the given block to be plotted. The blocks are plotted successively on the same graph. Default to NULL (all the columns are plotted).

add

Logical defining if the frame of the plot is plotted (add = FALSE; default) or not (add = TRUE). This allows to add new observations to a plot without red-building the frame.

...

Other arguments to pass in functions plot or lines

.

Value

A plot (see examples).

Examples


data(datcass)

X <- datcass$Xu

n <- nrow(X)

plotsp(X)
plotsp(X, col = "grey")
plotsp(X, col = "lightblue", 
  xlim = c(500, 1500),
  xlab = "Wawelength (nm)", ylab = "Absorbance")

### See: ?hcl.colors, hcl.pals()
col <- hcl.colors(n = n, alpha = 1, rev = FALSE, palette = "Grays")
#col <- hcl.colors(n = n, alpha = 1, rev = FALSE, palette = "Green-Orange")
#col <- terrain.colors(n, rev = FALSE)
#col <- rainbow(n, rev = FALSE, alpha = .2)
plotsp(X, col = col)

plotsp(X, col = "grey")
plotsp(X[23, , drop = FALSE], lwd = 2, add = TRUE)
plotsp(X[c(23, 16), ], lwd = 2, add = TRUE)

plotsp(X[5, , drop = FALSE], labels = TRUE)
plotsp(X[5, ])

plotsp(X[c(5, 61), ], labels = TRUE)

col <- hcl.colors(n = n, alpha = 1, rev = FALSE, palette = "Grays")
plotsp(X, col = col)
plotsp(X[5, , drop = FALSE], col = "red", lwd = 2, add = TRUE, labels = TRUE)

blocks <- list(1:500, 700:900)
plotsp(X, blocks = blocks)

###### Example with plotsp1
###### Scrolling plot of the loadings 

## After running the code, 
## type Enter in the R console for starting the scrolling,
## and type any character in the R console 

fm <- pca(X, ncomp = 50)
P <- fm$P
#plotsp1(t(P), ylab = "Value")


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.