Skip to contents

Produce a plot of the error between predicted and actual FTIR spectra.

Produisez un graphique de l'erreur entre les spectres IRTF prédits et réels.

Usage

plot_fit_residuals(
  ftir,
  fitted_peaks,
  lang = NA,
  call = rlang::caller_env(),
  ...
)

Arguments

ftir

A data.frame in long format with a single FTIR spectra in columns `sample_id`, `wavenumber`, and `absorbance`.

Un data.frame au format long avec un seul spectre IRTF dans les colonnes `sample_id`, `wavenumber`, et `absorbance`.

fitted_peaks

An object from [fit_peaks()]. Should match the provided sample in `ftir`.

Un objet de [fit_peaks()]. Doit correspondre à l'échantillon fourni dans `ftir`.

lang

An optional argument for language. If set to one of `fr`, `french`, `francais`, or `français` the axis and default plot and legend titles will change to french. If non-default legend or plot titles are provided they are used as-is. You can also provide `en`, `english` or `anglais`, or (the default) `NA` will use the default language from user options. To set a permanent default, set `options("PlotFTIR.lang" = "en")` or `options("PlotFTIR.lang" = "fr")` for English or French, respectively.

Un argument optionnel pour la langue. S'il vaut `Fr`, `French`, `Francais`, ou `Français`, l'axe et les titres par défaut de le tracé et du légende seront en français. Si des titres du légende ou de tracé autres que ceux par défaut sont fournis, ils seront utilisés tels quels. Vous pouvez aussi fournir `en`, `english` ou `anglais`, ou (le défaut) `NA` qui utilisera le langue par défaut des options de l'utilisateur. Pour définir une valeur par défaut permanente, mettez `options("PlotFTIR.lang" = "en")` ou `options("PlotFTIR.lang" = "fr")` pour l'anglais ou le français, respectivement.

call

(`environment`) The caller environment for error messages. L'environnement de l'appelant pour les messages d'erreur.

...

optional argument `fitted_sample_name` for naming the fitted peaks on the plot, or extra parameters to pass to [PlotFTIR::plot_ftir()].

Argument optionnel `fitted_sample_name` pour nommer les pics ajustés sur le graphique, ou des paramètres supplémentaires à passer à [PlotFTIR::plot_ftir()].

Value

A [PlotFTIR::plot_ftir()] graphic with residuals plotted against wavenumber.

Un graphique [PlotFTIR::plot_ftir()] avec les résidus tracés en fonction du nombre d'ondes.

Examples

# Load the isopropanol sample spectrum from the PlotFTIR package
ftir_data <- PlotFTIR::sample_spectra[
  PlotFTIR::sample_spectra$sample_id == "isopropanol",
]

# Choose a subset of the data (reducing run time)
ftir_data <- ftir_data[
  ftir_data$wavenumber < 1500 & ftir_data$wavenumber > 1000,
]

# First, fit the peaks using the default 'voigt' method
if (FALSE) { # \dontrun{
fitted_voigt <- fit_peaks(ftir_data, method = "voigt")
} # }

# --- Example 1: Plot residuals with default settings ---
if (FALSE) { # \dontrun{
plot_fit_residuals(ftir_data, fitted_voigt)
} # }

# --- Example 2: Plot residuals with custom titles in French ---
if (FALSE) { # \dontrun{
plot_fit_residuals(
  ftir_data,
  fitted_voigt,
  lang = "fr",
  plot_title = c(
    "R\u00e9sidus de l'ajustement",
    "Diff\u00e9rence entre le spectre et l'ajustement Voigt"
  )
)
} # }