View source: R/contributions.R
| plot_contributions | R Documentation |
Plots the contributions of the variables to the Q residual or to the
T^2 of samples (see contributions()) against wavelength, one
panel per sample, and labels the wavelengths that contribute most, with
the emission lines they match when a line list is given.
plot_contributions(
x,
samples = NULL,
top = 10,
lines = NULL,
tol = 0.1,
spectra = NULL,
span = 5,
interactive = FALSE,
title = NULL,
wavelength = NULL,
xlab = NULL,
ylab = NULL,
base_size = 11,
linewidth = 0.3
)
x |
An object returned by |
samples |
The samples to show (row numbers of |
top |
The number of peaks labeled per component (per panel). Default is 10; use 0 for no labels. |
lines |
Optional line list returned by |
tol |
The largest distance, in nm, between a peak and a line it matches. Default is 0.1. |
spectra |
Optional spectra (a data frame or matrix with the variables of the model, other columns being ignored) or a single spectrum (a named numeric vector), whose mean is drawn in grey behind each panel, rescaled to it, to show whether a peak is on an emission line. |
span |
The half-width, in channels, of the window in which a peak is a local extremum. Default is 5. |
interactive |
If |
title |
The plot title. |
wavelength |
Optional ( |
xlab, ylab |
The axis titles. Default are |
base_size |
The size of the text, in points. Default is 11; the peak labels scale with it. Ignored for interactive plots. |
linewidth |
The width of the bars (or, for interactive plots, of the line) drawn at each variable. Default is 0.3. |
Each contribution is drawn red above zero (the sample is higher than the
model, or than the reference samples) and blue below. The top largest
positive and negative local extrema are labeled, as in plot_loadings():
in bold with the nearest line of lines within tol nm. The mean
spectrum can be drawn in grey behind each panel, rescaled to it.
A ggplot object, or a plotly object if interactive = TRUE.
Christian L. Goueguel
contributions(), plot_loadings(), libs_lines()
spectra_id <- forageLIBS |> dplyr::select(1:2) |> names()
minerals <- forageLIBS |> dplyr::select(3:14) |> names()
spectra <- forageLIBS |> dplyr::select(-dplyr::all_of(c(spectra_id, minerals)))
set.seed(1)
fit <- robpca(spectra, ncomp = 3)
q <- contributions(fit, data = spectra, samples = c(49, 127), reference = "regular")
plot_contributions(q, spectra = spectra)
# the 390-400 nm window: the Ca II H and K lines
plot_contributions(q, spectra = spectra, wavelength = c(390, 400), top = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.