Skip to contents

Produces a plot of components of the peak fitting results.

Produit un graphique des composantes des résultats de l'ajustement des pics.

Usage

plot_components(
  ftir,
  fitted_peaks,
  plot_fit = FALSE,
  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`.

plot_fit

Boolean, whether to plot the peak fit (default FALSE)

Booléen, pour savoir s'il faut tracer l'ajustement du pic (par défaut FALSE)

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] graphic with residuals plotted against wavenumber

Un graphique [PlotFTIR] 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 components only (default) ---
if (FALSE) { # \dontrun{
plot_components(ftir_data, fitted_voigt)
} # }

# --- Example 2: Plot components AND the overall fitted sum ---
if (FALSE) { # \dontrun{
plot_components(ftir_data, fitted_voigt, plot_fit = TRUE)
} # }

# --- Example 3: Plot components and fit with custom titles and name ---
if (FALSE) { # \dontrun{
plot_components(
  ftir_data,
  fitted_voigt,
  plot_fit = TRUE,
  plot_title = c("Isopropanol Peak Fit", "Voigt Components"),
  legend_title = "Spectrum Type",
  fitted_sample_name = "Total Fit (Voigt)"
)
} # }

# --- Example 4: Plot components in French ---
if (FALSE) { # \dontrun{
plot_components(ftir_data, fitted_voigt, plot_fit = TRUE, lang = "fr")
} # }