
hyperSpec Plotting functions Claudia Beleites <[email protected]> DIA Raman Spectroscopy Group, University of Trieste/Italy (2005 { 2008) Spectroscopy Imaging, IPHT, Jena/Germany (2008 { 2016) ¢ OPV,¨ JKI, Berlin/Germany Chemometric Consulting and Chemometrix GmbH, W¨olfersheim/Germany October 5, 2017 Reproducing the Examples in this Vignette All spectra used in this manual are installed automatically with hyperSpec. Note that some definitions are executed in vignette.defs, and others invisibly at the beginning of the file in order to have the code as similar as possible to interactive sessions. Contents 1 Predefined functions2 2 Arguments for plot5 3 Spectra 8 3.1 Stacked spectra........................................... 10 4 Calibration Plots, (Depth) Profiles, and Time Series Plots 12 4.1 Calibration plots.......................................... 12 4.2 Time series and other Plots of the Type Intensity-over-Something............ 13 5 Levelplot 14 6 Spectra Matrix 14 7 False-Colour Maps: plotmap 16 8 3D plots (with rgl) 20 9 Using ggplot2 with hyperSpec objects 21 10 Troubleshooting 22 10.1 No output is produced...................................... 22 1 11 Interactive Graphics 22 11.1 spc.identify: finding out wavelength, intensity and spectrum.............. 23 11.2 map.identify: finding a spectrum in a map plot...................... 23 11.3 map.sel.poly: selecting spectra inside a polygon in a map plot............. 23 11.4 Related functions provided by base graphics and lattice.................. 23 Suggested Packages latticeExtra: available deldir: available rgl: available ggplot2 : available In addition tripack, and latticist are mentioned, but not used in this vignette. Preliminary Calculations For some plots of the chondro dataset, the pre-processed spectra and their cluster averages one standard deviation are more suitable: § > chondro.preproc <- chondro - spc.fit.poly.below (chondro) > chondro.preproc <- chondro.preproc / rowMeans (chondro) > chondro.preproc <- chondro.preproc - quantile (chondro.preproc, 0.05) > cluster.cols <- c ("dark blue", "orange", "#C02020") > cluster.meansd <- aggregate (chondro.preproc, chondro$clusters, mean_pm_sd) > cluster.means <- aggregate (chondro.preproc, chondro$clusters, mean) For details about the pre-processing, please refer to the example work flow in vignette ("chon- dro"), or the help ? chondro. 1 Predefined functions hyperSpec comes with 6 major predefined plotting functions. plot main switchyard for most plotting tasks levelplot hyperSpec has a method for lattice[? ] function levelplot plotspc plots spectra plotmat plots the spectra matrix plotc calibration plot, time series, depth profile plotc is a lattice function plotmap more specialized version of levelplot for map or image plots. plotmap is a lattice function plotvoronoi more specialized version of plotmap that produces Voronoi tesselations. plotvoronoi is a lattice function 2 plotmap, plotvoronoi, and levelplot are lattice functions. Therefore, in loops, functions, Sweave chunks, etc. the lattice object needs to be printed explicitly by e. g. print (plotmap (object)) (R FAQ: Why do lattice/trellis graphics not work?). 3 plotspc plots the spectra, i. e. the intensities $spc over the wave- 700 lengths @wavelength. 500 > plotspc (flu) a.u. l f I 300 100 410 430 450 470 490 λ nm plotmat 700 plots the spectra, i. e. the colour coded intensities $spc over 6 600 the wavelengths @wavelength and the row number. 5 500 > plotmat (flu) 4 400 row 3 300 200 2 100 1 0 420 440 460 480 λ nm plotc plots an intensity over a single other data column, e. g. 200 ● ● • calibration 150 ● time series a.u. • l f 100 ● I ● • depth profile 50 ● > plotc (flu) 0.05 0.10 0.15 0.20 0.25 0.30 c / (mg / l) levelplot plots a false colour map, defined by a formula. 500 > levelplot (spc ~ x * y, chondro, aspect = "iso") 15 450 Warning: Only first wavelength is used for plot- 10 400 ting y 5 350 0 300 250 −10 0 10 20 x 4 plotmap plotmap is a specialized version of levelplot. It uses a 850 800 single value (e. g. average intensity or cluster membership) 15 750 over two data columns (default $x and $y) 10 700 > plotmap (chondro) 650 y 5 600 550 0 500 450 400 −10 0 10 20 x plotvoronoi Function plotvoronoi is a special version of plotmap that produces Voronoi diagram of the hyperSpec object. 15 cell > plotvoronoi (sample (chondro, 300), clusters ~ x * y) 10 y lacuna 5 0 matrix −10 0 10 20 x 2 Arguments for plot hyperSpec's plot method uses its second argument to determine which of the specialized plots to produce. This allows some handy abbreviations. All further arguments are handed over to the function actually producing the plot. plot (x, "spc") is equivalent to plotspc (flu) 700 > plot (flu, "spc") 500 a.u. l f I 300 100 410 430 450 470 490 λ nm 5 plot (x, "spcmeansd") plots mean spectrum 1 standard deviation > plot (chondro.preproc,§ "spcmeansd") 0.20 I / a.u. 0.10 0.00 600 800 1000 1300 1600 − ∆~ν cm 1 plot (x, "spcprctile") plots median, 16th and 84th percentile for each wavelength. th th th 0.20 For Gaussian distributed data, 16 , 50 and 84 percentile are equal to mean standard deviation. Spectroscopic data frequently are not Gaussian§ distributed. The percentiles give 0.10 I / a.u. a better idea of the true distribution. They are also less sensitive to outliers. > plot (chondro.preproc, "spcprctile") 0.00 600 800 1000 1300 1600 − ∆~ν cm 1 plot (x, "spcprctl5") like "spcprctl" plus 5th and 95thpercentile. > plot (chondro.preproc, "spcprctl5") 0.30 I / a.u. 0.15 0.00 600 800 1000 1300 1600 − ∆~ν cm 1 plot (x, "c") ● 200 > plot (flu, "c") ● is equivalent to plotc (flu) 150 ● a.u. l f 100 ● I ● 50 ● 0.05 0.10 0.15 0.20 0.25 0.30 c / (mg / l) 6 plot (x, "ts") plots a time series plot 75000 ●●●●●● ●●●●●●●● ●●●●●●●●●●●●●●●●● ●●●●●●●●●●●●●●●●●●●●● ● ● > plot (laser [,, 405], "ts") 70000 ● ● ● ●● ● ● ● ● equivalent to plotc (laser, spc ~ t) 65000 ● ● ● ● ● ● ●● ●●● 60000 ● ● ●● I / a.u. ● ● 55000 ● ● 50000 ●● 0 1000 2000 3000 4000 5000 t / s plot (x, "depth") plots a depth profile plot ● 20 ● > depth.profile <- new ("hyperSpec", ● ● + spc = as.matrix (rnorm (20) + 1:20), 15 ● ● ● ● + data = data.frame (z = 1 : 20), ● ● ● + labels = list (spc = "I / a.u.", 10 ● I / a.u. ● + z = expression (`/` (z, mu*m)), ● ● 5 ● ● + .wavelength = expression (lambda))) ● ● ● > plot (depth.profile, "depth") 5 10 15 20 the same as plotc (laser, spc ~ z) z µm plot (x, "mat") 80000 plots the spectra matrix. 80 > plot (laser, "mat") 60000 60 Equivalent to 40000 > plotmat (laser) row 40 A lattice alternative is: 20000 20 > levelplot (spc ~ .wavelength * .row, laser) 0 404.6 405.0 405.4 405.8 λ nm plot (x, "map") is equivalent to plotmap (chondro) 850 800 > plot (chondro, "map") 15 750 10 700 650 y 5 600 550 0 500 450 400 −10 0 10 20 x 7 plot (x, "voronoi") 800 750 > plot (sample (chondro, 300), "voronoi") 15 700 See plotvoronoi 10 650 y 600 5 550 500 0 450 400 −10 0 10 20 x 3 Spectra plotspc plotspc offers a variety of parameters for customized plots. To plot ... particular wavelength range if only one wavelength range is needed, the extract command 50000 (see vignette ("introduction")) is handiest: > plotspc (paracetamol [,, 700 ~ 1200]) wavelengths. If wl.range already contains indices use 30000 I / a.u. wl.index = TRUE. 10000 700 800 900 1000 1100 1200 − ∆~ν cm 1 more wavelength ranges use wl.range = list (600 ~ 1800, 2800 ~ 3100). Cut 50000 the wavelength axis appropriately with xoffset = 750 > plotspc (paracetamol, + wl.range = c (300 ~ 1800, 2800 ~ max), I / a.u. + xoffset = 750) 20000 If available, the package plotrix[1] is used to produce the cut 0 mark. 400 800 1200 1600 2800 3200 − ∆~ν cm 1 with reversed abscissa use wl.reverse = TRUE 50000 > plotspc (paracetamol, wl.reverse = TRUE ) I / a.u. 20000 0 3000 2000 1000 0 − ∆~ν cm 1 8 in different colours use col = vector.of.colours 700 > plotspc (flu, col = matlab.dark.palette (6)) 500 a.u. l f I 300 100 410 430 450 470 490 λ nm dots instead of lines ● use lines.args = list (pch = 20, type = "p") ●● ●● ●● ●● ●● > plotspc (paracetamol [,, 2800 ~ 3200], 2500 ● ● ●● ● ●●● ● ● ●● ● ● ● + lines.args = list (pch = 20, type = "p")) ● ● ● ● ● ●● ● ●● ●● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● 1500 ● ● ● ● I / a.u. ● ● ●● ● ● ● ●● ●●● ●● ● ●● ● ●●●●● ● ● ● ●●●●●●●● ● ●● ● ● ●●●●● ●● ●● ●● ● ● ● ●●●● ● ●●●● ●●●●● ● ●●●● ● ●●●●●●●●●●●● ●●●●●●●●●● ●●●●●●●●●●●● ●●●●● ● ●●● ●●●●●●●●●●●●●●● ●●●●●●●●●●●●● ●●●●●● ●● ● ●●●●●●●●●●●●●●●●●●●●● ●●● ●● ●●● ●●●●● ● ● ●●●●●●●●●●●●●● ● ● ●● ●●● ●●●●●● ●●● ●●●●●●●●●●●●●●●●●●●●●●●●●●● ●●● ●●● ●●●●●●●● 500 ● 2800 2900 3000 3100 3200 − ∆~ν cm 1 mass spectra use lines.args = list (type = "h") 12000 > plot (barbiturates [[1]], lines.args = list (type = "h")) a. u. 6000 I 2000 30 50 70 90m u 110 130 150 z e more spectra into an existing plot use add = TRUE > plotspc (chondro [ 30,,]) 1000 > plotspc (chondro [300,,], add = TRUE, col = "blue") I / a.u. 600 200 600 800 1000 1300 1600 − ∆~ν cm 1 9 Summary characteristics func may be used to calculate summary characteristics prior to plotting. To plot e. g. the standard deviation of the spec- tra, use: 0.08 > plotspc (chondro.preproc, func = sd) I / a.u. 0.04 0.00 600 800 1000 1300 1600 − ∆~ν cm 1 with different line at I 0 Æ zeroline takes a list with parameters to abline, NA sup- 50000 presses the line. > plotspc (paracetamol, + zeroline = list (col = "red")) I / a.u. 20000 0 0 500 1500 2500 − ∆~ν cm 1 adding to a spectra plot plotspc uses base graphics. After plotting the spectra, more content may be added to the graphic by abline, lines, points, etc. > plot (laser, "spcmeansd") 40000 I / a.u. > abline (v = c(405.0063, 405.1121, 405.2885, 405.3591), + col = c("black", "blue", "red", "darkgreen")) 0 404.6 404.9 405.2 405.5 405.8 λ nm 3.1 Stacked spectra stacked use stacked = TRUE > plotspc (cluster.means, 3 + col = cluster.cols, + stacked = TRUE) 2 I / a.u. 1 600 800 1000 1300 1600 − ∆~ν cm 1 10 Stacking groups of spectra The spectra to be stacked can be grouped: stacked = factor .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages24 Page
-
File Size-