library(mdatools)
### Examples of using mdaplot function
## 1. Make a line plot for y = x^2 with different x values for each line
x1 = seq(-10, 10, length = 100)
y1 = x1^2
x2 = seq(-9, 9, length = 100) + 1
y2 = x2^2 * 1.2
x3 = seq(-8, 8, length = 100) + 2
y3 = x3^2 * 1.4
mdaplot(cbind(x1, y1, x2, y2, x3, y3), type = 'l', single.x = FALSE)
## 2. Change tick values and labels for x axis
mdaplot(cbind(x1, y1, x2, y2, x3, y3), type = 'l', single.x = FALSE,
xticks = c(-8, 0, 8), xticklabels = c('Negative', 'Zero', 'Positive'))
## 3. Make a line plot of the spectra with coloring by concentration of first component
## using different color maps
data(simdata)
# first column of matrix val will contain the wavelength
# and the last columns - spectra from calibration set
val = cbind(simdata$wavelength, t(simdata$spectra.c))
# concentration will be used for color groups
c1 = simdata$conc.c[, 1]
par(mfrow = c(2, 2))
mdaplot(val, type = 'l', cgroup = c1)
mdaplot(val, type = 'l', cgroup = c1, colmap = 'gray', show.colorbar = FALSE)
mdaplot(val, type = 'l', cgroup = c1, colmap = c('red', 'green'))
mdaplot(val, type = 'l', cgroup = c1, colmap = c('#ffff00', '#00ffff'))
par(mfrow = c(1, 1))
## 3. Show scatter plots from spectral data with color groups and other parameters
## see how limits are adjusted if show.lines option is used
nobj = 30
# concentration is used for color groups
c1 = simdata$conc.c[1:nobj, 1]
# x values are absorbance of waveband 100, y values - absorbance for waveband 110
pdata = cbind(
simdata$spectra.c[1:nobj, 100, drop = FALSE],
simdata$spectra.c[1:nobj, 110, drop = FALSE])
par(mfrow = c(2, 2))
mdaplot(pdata, cgroup = c1, main = 'Spectra', show.lines = c(0.1, 0.06))
mdaplot(pdata, cgroup = c1, main = 'Spectra', show.lines = c(0.06, 0.01))
mdaplot(pdata, cgroup = c1, xlab = '309 nm', ylab = '319 nm', main = 'Spectra', show.labels = TRUE)
mdaplot(pdata, col = 'red', pch = 17, show.labels = TRUE, labels = paste('Obj', 1:nobj))
par(mfrow = c(1, 1))
Run the code above in your browser using DataLab