Skip to contents

Package overview

ggspectra ggspectra-package
ggspectra: Extensions to 'ggplot2' for Radiation Spectra

Plot basics

Function ggplot() is a generic method defined in package ‘ggplot2’, especialisations defined in package ‘ggspectra’ provide default aes() for spectral classes.

Layer: Geoms

Geoms, short for geometric objects, describe the type of plot you will produce.

Spectral data plots.

Layer: Statistics

It is often useful to summarize spectral data before plotting, and that is what these transformations do.

Calculate colours from wavelength.
Find quantity value for target wavelength value.
Find wavelength for target quantity value.
stat_peaks() stat_valleys()
Find peaks and valleys.
stat_label_peaks() stat_label_valleys()
Label peaks and valleys.
Find spikes
Draw colour boxes for wavebands
Integrate ranges under curve.
Integrate ranges under curve.
Integrate ranges under spectral curve.
stat_wb_irrad() stat_wb_e_irrad() stat_wb_q_irrad()
Integrate irradiance for wavebands.
Label ranges under spectral curve.
Integrate ranges under curve.
Integrate ranges under spectral curve.
stat_wb_sirrad() stat_wb_e_sirrad() stat_wb_q_sirrad()
Integrate spectral irradiance for wavebands.
Integrate ranges under spectral curve.
stat_wl_strip() wl_guide()
Calculate colours from wavelength.
Average area under curve for regions.


Scales control the mapping between data and aesthetics. The scales defined in package ‘ggspectra’ are continuous scales with defaults suitable for spectral data.

Automatic plot creation

Autoplot methods for spectra and a function for color-patch charts. They all return gg objects.

autoplot(<raw_spct>) autoplot(<raw_mspct>)
Create a complete ggplot for raw detector-counts spectra.
autoplot(<calibration_spct>) autoplot(<calibration_mspct>)
Create a complete ggplot for an irradiation calibration spectrum.
autoplot(<cps_spct>) autoplot(<cps_mspct>)
Create a complete ggplot for detector-counts per second spectra.
autoplot(<source_spct>) autoplot(<source_mspct>)
Create a complete ggplot for light-source spectra.
autoplot(<response_spct>) autoplot(<response_mspct>)
Create a complete ggplot for a response spectrum.
autoplot(<filter_spct>) autoplot(<filter_mspct>)
Create a complete ggplot for a filter spectrum.
autoplot(<reflector_spct>) autoplot(<reflector_mspct>)
Create a complete ggplot for a reflector spectrum.
autoplot(<object_spct>) autoplot(<object_mspct>)
Create a complete ggplot for a object spectrum.
autoplot(<generic_spct>) autoplot(<generic_mspct>)
Create a complete ggplot for generic spectral data.
Create a complete ggplot for a waveband descriptor.
autotitle() ggtitle_spct()
Add title, subtitle and caption to a spectral plot
set_annotations_default() set_w.band_default()
Set defaults for autoplot annotations
Create a color checker chart

Helper functions

Formatters, International System of units, unit conversions.

Chose black vs. white color based on weighted mean of RGB channels
exponent2prefix() exponent2factor() exponent2prefix_name() prefix_name2exponent() prefix2exponent() has_SI_prefix() nearest_SI_exponent()
SI unit prefixes
SI_pl_format() SI_plain()
Formatter for plain labels discounting for SI multipliers
SI_tg_format() SI_tagged()
Formatter for tagged labels using SI multipliers
w_number() w_frequency()
Deprecated functions
axis_labels() axis_labels_uk() axis_labels_uk_comma() axis_labels_none()
Default text for axis labels
w_length_label() w_number_label() w_frequency_label() w_energy_eV_label() w_energy_J_label()
Wave- axis labels
Raw-counts axis labels
Counts-per-second axis labels
Rfr_label() Rfr_specular_label()
Reflectance axis labels
A_label() A_internal_label() A_total_label()
Absorbance axis labels
Tfr_label() Tfr_internal_label() Tfr_total_label()
Transmittance axis labels
Afr_label() Rfr_total_label()
Absorptance axis labels
s.e.irrad_label() s.q.irrad_label()
spectral irradiance axis labels
s.e.response_label() s.q.response_label() s.e.action_label() s.q.action_label()
spectral response and action axis labels
Calibration multipliers axis labels
Multiple plot function
plot(<generic_spct>) plot(<generic_mspct>) plot(<waveband>)
Deprecated plot methods