{"id":32203008,"url":"https://github.com/nrcan/plotftir","last_synced_at":"2026-02-21T18:04:29.424Z","repository":{"id":260674665,"uuid":"859900908","full_name":"NRCan/PlotFTIR","owner":"NRCan","description":"R Code for pretty plotting of FTIR spectra","archived":false,"fork":false,"pushed_at":"2025-08-25T15:49:41.000Z","size":12307,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-19T07:34:27.920Z","etag":null,"topics":["chemometrics","datavis","ftir"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NRCan.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-19T13:28:25.000Z","updated_at":"2025-08-25T15:49:45.000Z","dependencies_parsed_at":"2025-02-06T13:21:24.284Z","dependency_job_id":"ae80f7df-b2c0-4044-9b02-4c0dc0e4a12d","html_url":"https://github.com/NRCan/PlotFTIR","commit_stats":null,"previous_names":["nrcan/plotftir"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/NRCan/PlotFTIR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NRCan%2FPlotFTIR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NRCan%2FPlotFTIR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NRCan%2FPlotFTIR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NRCan%2FPlotFTIR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NRCan","download_url":"https://codeload.github.com/NRCan/PlotFTIR/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NRCan%2FPlotFTIR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29689644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T15:51:39.154Z","status":"ssl_error","status_checked_at":"2026-02-21T15:49:03.425Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chemometrics","datavis","ftir"],"created_at":"2025-10-22T04:25:56.747Z","updated_at":"2026-02-21T18:04:29.417Z","avatar_url":"https://github.com/NRCan.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"66.67%\",\n  dpi = 300\n)\nlibrary(magrittr)\nlibrary(PlotFTIR)\n```\n\n# PlotFTIR \u003cimg src='man/figures/PlotFTIR_logo.png' align=\"right\" width=\"25%\" min-width=\"120px\"/\u003e\n\n([Français](#introduction-et-installation))\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/NRCan/PlotFTIR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/NRCan/PlotFTIR/actions/workflows/R-CMD-check.yaml)\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![Coveralls test coverage](https://coveralls.io/repos/github/NRCan/PlotFTIR/badge.svg)](https://coveralls.io/github/NRCan/PlotFTIR)\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/PlotFTIR)](https://cran.r-project.org/package=PlotFTIR)\n\u003c!-- badges: end --\u003e\n\n## Introduction and Installation\nThe goal of `PlotFTIR` is to easily and quickly kick-start the production of journal-quality Fourier Transform Infra-Red (FTIR) spectral plots in R using ggplot2. The produced plots can be published directly or further modified by ggplot2 functions.\n\nYou can install the development version of `PlotFTIR` from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"NRCan/PlotFTIR\")\n\nlibrary(PlotFTIR)\n```\n\n## Example Plots\n\nThis is a basic example which shows you how to plot a prepared set of FTIR spectra:\n\n```{r basic_plot_en}\nbiodiesel_plot \u003c- plot_ftir(biodiesel)\nbiodiesel_plot\n```\n\nYou can also plot spectra in a stacked/offset manner instead of overlaid:\n```{r stack_plot_en}\n# Generate a plot\nplot_ftir_stacked(biodiesel)\n```\n\nNote the default plot and legend titles are in english but can be automatically changed to french defaults by supplying the `lang = 'fr'` argument to plot creation functions.\n\nPlots can be manipulated, for example, by zooming in on a range:\n```{r biodiesel_zoom_en}\n# Zoom to a specified range of 1850 to 1650 cm^-1\nzoom_in_on_range(biodiesel_plot, c(1650, 1850))\n```\n\nSome FTIR plots have a compressed low-energy portion of the graph which you might wish to zoom in on. You can achieve this by the following:\n```{r biodiesel_compress_en}\n# compress the data with wavenumbers above 2000 (to the left of 2000 on the\n# plot) by a factor of 5\ncompress_low_energy(biodiesel_plot, cutoff = 2000, compression_ratio = 5)\n```\n\nYou can also add marker lines (with labels) at specific wavenumbers on the plots, controlling their line or text properties as needed. Similarly, a shaded band can be added to indicate a region.\n```{r biodiesel_labelled_en}\nbiodiesel_marked \u003c- add_wavenumber_marker(biodiesel_plot,\n  wavenumber = 1742,\n  text = \"C=O Stretch\",\n  label_aesthetics = list(\"color\" = \"red\")\n) \nadd_band(biodiesel_marked, c(2750,3050), \"C-H Stretch\")\n```\n\nIf the need arises to rename samples listed in the legend, this is possible via `rename_plot_sample_ids()`. Samples must be listed in the rename vector with the format `\"new name\" = \"old name\"`. \n```{r biodiesel_rename_en}\nnew_names \u003c- c(\n  \"0.0% Biodiesel\" = \"biodiesel_0\",\n  \"0.25% Biodiesel\" = \"biodiesel_0_25\",\n  \"0.50% Biodiesel\" = \"biodiesel_0_50\",\n  \"1.0% Biodiesel\" = \"biodiesel_1_0\",\n  \"2.5% Biodiesel\" = \"biodiesel_2_5\",\n  \"5.0% Biodiesel\" = \"biodiesel_5_0\",\n  \"7.5% Biodiesel\" = \"biodiesel_7_5\",\n  \"10.0% Biodiesel\" = \"biodiesel_10_0\",\n  \"Commercial B0.5\" = \"biodiesel_B0_5\",\n  \"Commercial B5\" = \"biodiesel_B5\",\n  \"Unknown Biodiesel\" = \"diesel_unknown\"\n)\nrename_plot_sample_ids(biodiesel_plot, new_names)\n```\n\nA helper function for the renaming is provided (see the documentation for `get_plot_sample_ids()`).\n\nSpecific sample(s) can be highlighted (other samples greyed out) by calling `highlight_sample()`. \n\nFinally, plot legends are customizable (for basic changes) through a helper function `move_plot_legend()`.\n\n## Data Sets\n\nThe package contains two datasets to provide example spectra for plotting:\n* `biodiesel` is a set of diesels with 0 to 10 % FAMEs (fatty acid methyl esters; biodiesel) content, plus two known and one unknown diesel spectra.\n* `sample_spectra` is a set of random FTIR spectra which includes spectra of pure toluene, isopropanol, and heptanes, as well as white printer paper and a polystyrene film.\n\nAn example of the `biodiesel` data set is below:\n```{r biodiesel_head_en}\nhead(biodiesel)\n```\n\n## Tidy Plot Production\n\nNote that because most functions return a data type similar to what is provided, tidy-eval is possible (using the base R pipe `|\u003e` or [`magrittr` pipe function](https://magrittr.tidyverse.org/reference/pipe) `%\u003e%`). \n\n```{r tidy_en, warning=FALSE}\nlibrary(magrittr)\n\nnew_ids \u003c- c(\n  \"Toluene\" = \"toluene\", \"C7 Alkane\" = \"heptanes\", \"IPA\" = \"isopropanol\",\n  \"White Paper\" = \"paper\", \"PS Film\" = \"polystyrene\"\n)\n\nsample_spectra |\u003e\n  absorbance_to_transmittance() |\u003e\n  plot_ftir(plot_title = \"Example FTIR Spectra\") |\u003e\n  zoom_in_on_range(zoom_range = c(3800, 800)) |\u003e\n  compress_low_energy(compression_ratio = 4) |\u003e\n  add_wavenumber_marker(\n    wavenumber = 1495,\n    text = \"C-C Aromatic\",\n    line_aesthetics = list(\"linetype\" = \"dashed\"),\n    label_aesthetics = list(\"color\" = \"#7e0021\")\n  ) |\u003e\n  add_wavenumber_marker(\n    wavenumber = 3340,\n    text = \"O-H Alcohol\",\n    line_aesthetics = list(\"linetype\" = \"dotted\"),\n    label_aesthetics = list(\"color\" = \"#ff420e\")\n  ) |\u003e\n  rename_plot_sample_ids(sample_ids = new_ids) |\u003e\n  move_plot_legend(position = \"bottom\", direction = \"horizontal\")\n```\n\n## Data Manipulation\n\nFTIR spectral data can be converted between absorbance and transmittance. Only one type of data can exist in a data.frame and be plotted. The functions `absorbance_to_transmittance()` and `transmittance_to_absorbance()` perform these conversions.\n\n```{r convert_datatype_en}\nbiodiesel_transm \u003c- absorbance_to_transmittance(biodiesel)\nhead(biodiesel_transm)\n```\n\nFunctions are provided for adjusting the baseline of spectra, adding or subtracting scalar values from entire spectra, normalizing spectra, and averaging spectra, see:\n* `recalculate_baseline()`\n* `add_scalar_value()` and `subtract_scalar_value()`\n* `normalize_spectra()`\n* `average_spectra()`\n\n## Reading Files\n\n`PlotFTIR` can read .csv, .asp, and .jdx file types. The .csv or .jdx files should contain only one spectra, with columns for `wavenumber` and `absorbance` or `transmittance.` The .asp files should be according to the file specifications (not modified by the user).\n\n## Interfacing With `ir` and `ChemoSpec` Packages\n\n`PlotFTIR` has functions to interface with the `ir` package by Henning Teickner. This package offers complex baseline capabilities, smoothing, and more data analysis tools. More information on the `ir` package is available in their [documetation (via CRAN)](https://cran.r-project.org/package=ir). There is also capabilities to interface with `ChemoSpec` package by Bryan Hanson, which supports advanced statistics and chemometrics of spectral data. More information at [the `ChemoSpec` documentation](https://bryanhanson.github.io/ChemoSpec/index.html).\n\n## Citing This Package\n\nPlease cite this package in any journal articles containing images produced by way of the package. If installed from GitHub or CRAN the date field will be properly filled with the publishing year.\n\n```{r cite-en, warning=FALSE}\ncitation(\"PlotFTIR\")\n```\n\n## Language Settings\n\nThe package has the ability to change language from English to French for plots on a per-plot basis (call `plot_ftir()` functions with `lang = 'en'` or `lang = 'fr` arguments). In addition, the default language can be set to English or French by setting `options('PlotFTIR.lang' = 'en')` or `options('PlotFTIR.lang' = 'fr')` respectively. This can be added to your .RProfile to persist between R sessions.\n\n([English](#introduction-and-installation))\n\n## Introduction et installation\n\nLe but de `PlotFTIR` est de lancer facilement et rapidement la production des tracés de spectres de spectroscopie infrarouge à transformée de Fourier (IRTF) de qualité de revues scientifiques dans le system R en utilisant ggplot2. Les tracés produits peuvent être publiés directement ou modifiés par les fonctions ggplot2.\n\nVous pouvez installer la version de développement de `PlotFTIR` depuis [GitHub](https://github.com/) avec:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"NRCan/PlotFTIR\")\n\nlibrary(PlotFTIR)\n```\n\n## Exemples des tracés\nCeci est un example de base qui vous montre comment tracer un ensemble de spectres IRTF dejà preparé:\n\n```{r basic_plot_fr}\nlibrary(PlotFTIR)\nplot_ftir(sample_spectra, lang = \"fr\")\n```\n\nVous pouvez également tracer les spectres de manière empilée/décalée au lieu de les superposer :\n```{r stack_plot_fr}\nplot_ftir_stacked(biodiesel, plot_title = \"Spectre IRTF empilée\", lang = \"fr\")\n```\n\nNotez que les titres par défaut de tracé et du légende sont en anglais, mais qu'ils peuvent être automatiquement modifiés en français en fournissant l'argument `lang = 'fr'` aux fonctions de création de tracés.\n\nLes tracés peuvent être manipulés, par exemple, en zoomant sur une plage :\n```{r biodiesel_zoom_fr}\n# Générer un tracé\nbiodiesel_trace \u003c- plot_ftir(biodiesel, lang = \"fr\")\n# Zoom sur une plage spécifiée de 1850 à 1650 cm^-1\nzoom_in_on_range(biodiesel_trace, c(1650, 1850))\n```\n\nCertains tracés IRTF ont une partie compressée du graphique à faible énergie qui peuvent etre agrandie de la manière suivante :\n```{r biodiesel_compress_fr}\n# compresser les données avec des nombres d'onde supérieurs à 2000 (à gauche de\n# 2000 sur le tracé) d'un facteur 5\ncompress_low_energy(biodiesel_trace, cutoff = 2000, compression_ratio = 5)\n```\n\nVous pouvez également ajouter des lignes de marqueur (avec des étiquettes) à des numéros d'onde spécifiques sur les tracés, en contrôlant leurs propriétés de ligne ou de texte selon vos besoins. De même, une bande ombrée peut être ajoutée pour indiquer une région.\n```{r biodiesel_labelled_fr}\nbiodiesel_marked \u003c- add_wavenumber_marker(biodiesel_trace,\n  wavenumber = 1742,\n  text = \"C=O étirement\",\n  label_aesthetics = list(\"color\" = \"red\")\n) \nadd_band(biodiesel_marked, c(2750,3050), \"C-H étirement\")\n```\n\nS'il est nécessaire de renommer les échantillons répertoriés dans la légende, cela est possible via `rename_plot_sample_ids()`. Le vecteur de renommage doit avoir le format `\"nouveau nom\" = \"ancien nom\"`.\n\n```{r biodiesel_rename_fr}\nnouveau_noms \u003c- c(\n  \"0,0% Biodiesel\" = \"biodiesel_0\",\n  \"0,25% Biodiesel\" = \"biodiesel_0_25\",\n  \"0,50% Biodiesel\" = \"biodiesel_0_50\",\n  \"1,0% Biodiesel\" = \"biodiesel_1_0\",\n  \"2,5% Biodiesel\" = \"biodiesel_2_5\",\n  \"5,0% Biodiesel\" = \"biodiesel_5_0\",\n  \"7,5% Biodiesel\" = \"biodiesel_7_5\",\n  \"10,0% Biodiesel\" = \"biodiesel_10_0\",\n  \"B0,5 Commercial\" = \"biodiesel_B0_5\",\n  \"B5 Commercial\" = \"biodiesel_B5\",\n  \"Biodiesel Inconnu\" = \"diesel_unknown\"\n)\nrename_plot_sample_ids(biodiesel_trace, nouveau_noms)\n```\n\nUne fonction d'assistance pour le changement de nom est fournie (voir la documentation pour `get_plot_sample_ids()`).\n\nUn ou plusieurs échantillons spécifiques peuvent être mis en évidence (les autres échantillons étant grisés) en appelant `highlight_sample()`. \n\nEnfin, les légendes des tracés sont personnalisables (pour les modifications de base) via une fonction d'assistance `move_plot_legend()`.\n\n## Production de tracés \"tidy\" \n\nNotez que comme la plupart des fonctions renvoient un type de données similaire à celui qui est fourni, l'évaluation des données est possible (en utilisant [la fonction `magrittr` tuyau](https://magrittr.tidyverse.org/reference/pipe) `%\u003e%`).\n\n```{r tidy_fr, warning=FALSE}\nlibrary(magrittr)\n\nnouveaux_ids \u003c- c(\n  \"Toluène\" = \"toluene\", \"C7 alcane\" = \"heptanes\", \"alcool isopropylique\" = \"isopropanol\",\n  \"papier blanc\" = \"paper\", \"film de polystyrène\" = \"polystyrene\"\n)\n\nsample_spectra |\u003e\n  absorbance_to_transmittance() |\u003e\n  plot_ftir(plot_title = \"Exemple de spectres IRTF\", lang = \"fr\") |\u003e\n  zoom_in_on_range(zoom_range = c(3800, 800)) |\u003e\n  compress_low_energy(compression_ratio = 4) |\u003e\n  add_wavenumber_marker(\n    wavenumber = 1495,\n    text = \"C-C aromatique\",\n    line_aesthetics = list(\"linetype\" = \"dashed\"),\n    label_aesthetics = list(\"color\" = \"#7e0021\")\n  ) |\u003e\n  add_wavenumber_marker(\n    wavenumber = 3340,\n    text = \"O-H alcool\",\n    line_aesthetics = list(\"linetype\" = \"dotted\"),\n    label_aesthetics = list(\"color\" = \"#ff420e\")\n  ) |\u003e\n  rename_plot_sample_ids(sample_ids = nouveaux_ids) |\u003e\n  move_plot_legend(position = \"bottom\", direction = \"horizontal\")\n```\n\n## Production de tracés \"tidy\" \n\nNotez que, comme la plupart des fonctions renvoient un type de données similaire à celui fourni, une \"tidy-eval\" est possible.\n\n## Ensembles des données\n\nLe package contient deux ensembles de données pour fournir des exemples de spectres à tracer:\n* `biodiesel` est un ensemble de diesels avec une teneur en esters méthyliques d'acides gras (EMAGs) (ou biodiesel) de 0 à 10 %, plus deux spectres de diesel connus et un inconnu.\n* `sample_spectra` est un ensemble de spectres IRTF aléatoires qui comprennent des spectres de toluène pur, d'isopropanol et d'heptanes, ainsi que du papier d'imprimante blanc et un film de polystyrène.\n\nUn exemple de l'ensemble de données `biodiesel` est ci-dessous:\n```{r biodiesel_head_fr}\nhead(biodiesel)\n```\n\n## Manipulation de données\n\nLes données spectrales IRTF peuvent être converties entre l'absorbance et la transmission. Un seul type de données peut exister dans un data.frame et être tracé. Les fonctions `absorbance_to_transmittance()` et `transmittance_to_absorbance()` effectuent ces conversions.\n\n```{r convert_datatype_fr}\nbiodiesel_transm \u003c- absorbance_to_transmittance(biodiesel)\nhead(biodiesel_transm)\n```\n\nDes fonctions sont fournies pour ajuster la ligne de base des spectres, ajouter ou soustraire des valeurs scalaires de spectres entiers, normalisation des spectres, et calculer la moyenne des spectres, voir :\n* `recalculate_baseline()`\n* `add_scalar_value()` et `subtract_scalar_value()`\n* `normalize_spectra()`\n* `average_spectra()`\n\n## Lecture des fichiers\n\n`PlotFTIR` peut lire les fichiers de type .csv, .asp, et .jdx. Le fichier .csv ou .jdx ne doit contenir qu'un seul spectre, avec des colonnes pour le `wavenumber` et `absorbance` ou `transmittance`. Les fichiers .asp doivent être conformes aux spécifications du fichier (non modifiées par l'utilisateur).\n\n## Interfaçage avec le paquetage `ir`\n\n`PlotFTIR` possède des fonctions pour s'interfacer avec le paquet `ir` de Teickner. Ce package offre des capacités de lignes de base complexes, de lissage, et plus d'outils d'analyse de données. Plus d'informations sur le paquet `ir` sont disponibles dans leur [documetation (via CRAN)] (https://cran.r-project.org/package=ir). Il est également possible de s'interfacer avec le paquet `ChemoSpec` de Bryan Hanson, qui prend en charge les statistiques avancées et la chimiométrie des données spectrales. Plus d'informations sur [la documentation de `ChemoSpec`] (https://bryanhanson.github.io/ChemoSpec/index.html).\n\n## Citer ce paquet\n\nVeuillez citer ce paquet dans tout article de journal contenant des images produites à l'aide de ce paquet. Si le paquet est installé à partir de GitHub ou de CRAN, le texte de la date sera correctement rempli avec l'année de publication.\n\n```{r cite-fr, warning=FALSE}\ncitation(\"PlotFTIR\")\n```\n\n## Paramètres de langue\n\nLe paquetage a la capacité de changer la langue de l'anglais au français pour les tracés sur une base individuelle (appeler les fonctions `plot_ftir()` avec les arguments `lang = 'en'` ou `lang = 'fr'`). De plus, la langue par défaut peut être réglée sur l'anglais ou le français en réglant `options('PlotFTIR.lang' = 'en')` ou `options('PlotFTIR.lang' = 'fr')` respectivement. Ceci peut être ajouté à votre .RProfile pour persister entre les sessions R.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrcan%2Fplotftir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrcan%2Fplotftir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrcan%2Fplotftir/lists"}