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

melt_spectra

Melts the spectra data of a Spectra object and returns it as wide format.


Description

This function is very useful when wanting to plot spectra using the lattice or ggplot2 packages

Usage

melt_spectra(obj, attr=NULL, ...)

## S4 method for signature 'SpectraDataFrame'
melt_spectra(obj, attr = NULL, ...)

Arguments

obj

an object of class "Spectra" or inheriting from this class

attr

vector of id variables against which the spectra will be melted (see melt)

...

further arguments passed to or from other methods

Methods

x=Spectra

melt_spectra(obj, ...)

obj A Spectra object
... Ignored

x=SpectraDataFrame

melt_spectra(obj, attr=NULL, ...)

obj A SpectraDataFrame object
attr Character, the name of an attribute in the object data to split the spectra against.
... Ignored

Author(s)

Pierre Roudier pierre.roudier@gmail.com

References

Hadley Wickham (2011). The Split-Apply-Combine Strategy for Data Analysis. Journal of Statistical Software, 40(1), 1-29. URL http://www.jstatsoft.org/v40/i01/.

Examples

# Loading example data
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500

# Simple melt
r <- melt_spectra(australia)
head(r)

## Not run: 
# Melt against some factor (or continuous data), and plot
# using ggplot2

# Create some factor
australia$fact <- sample(
  LETTERS[1:3], 
  size = nrow(australia), 
  replace = TRUE
)
r <- melt_spectra(australia, attr = 'fact')

# Create plot
library(ggplot2)
p <- ggplot(r) + 
  geom_line(aes(x=wl, y=nir, group=id, colour=fact)) + 
  theme_bw()
print(p)

## End(Not run)

spectacles

Storing, Manipulating and Analysis Spectroscopy and Associated Data

v0.5-3
GPL-3
Authors
Pierre Roudier [aut, cre], Max Kuhn [ctb], Kristian Hovde Liland [ctb], Bjorn-Helge Mevik [ctb], Hadley Wickham [ctb], Raphael Viscarra Rossel [dtc]
Initial release
2021-01-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.