Learn R Programming

⚠️There's a newer version (0.3.16) of this package.Take me there.

ggspectra

The goal of ‘ggspectra’ is to make it easy to plot radiation spectra and similar data, such and transmittance, absorbance and reflectance spectra, producing fully annotated publication- and presentation-ready plots. It is an extension to packages ‘ggplot2’ and ‘photobiology’, and part of the ‘r4phototbiology’ suite.

Package ‘ggspectra’ provides stats, geoms, scales and functions to be used for plotting radiation-related spectra and annotating the plots with quantities derived from spectral data. All summary quantities implemented in ‘photobiology’ can be used for annotations including biologically effective irradiances and exposures.

Please, see the web site r4photobiology for details on other packages available as part of the suite, and on how to install them.

Example

This is a basic example which shows plotting using the most automatic approach.

library(photobiology)
library(ggspectra)
plot(sun.spct)

This second example uses the grammar of graphics approach, as implemented in ‘ggplot2’.

library(ggplot2)
photon_as_default()
ggplot(sun.spct) +
  geom_spct() +
  scale_y_s.q.irrad_continuous() +
  scale_x_wl_continuous(sec.axis = sec_axis_w_number()) +
  theme_bw()

Installation

Installation of the most recent stable version from CRAN:

install.packages("ggspectra")

Installation of the current unstable version from Bitbucket:

# install.packages("devtools")
devtools::install_bitbucket("aphalo/ggspectra")

Documentation

HTML documentation is available at (http://docs.r4photobiology.info/ggspectra/), including a User Guide.

News on updates to the different packages of the ‘r4photobiology’ suite are regularly posted at (https://www.r4photobiology.info/).

Two articles introduce the basic ideas behind the design of the suite and its use: Aphalo P. J. (2015) (https://doi.org/10.19232/uv4pb.2015.1.14) and Aphalo P. J. (2016) (https://doi.org/10.19232/uv4pb.2016.1.15).

A book is under preparation, and the draft is currently available at (https://leanpub.com/r4photobiology/). The book conatins many examples of plots created with ‘ggspectra’.

A handbook written before the suite was developed contains useful information on the quantification and manipulation of ultraviolet and visible radiation: Aphalo, P. J., Albert, A., Björn, L. O., McLeod, A. R., Robson, T. M., & Rosenqvist, E. (Eds.) (2012) Beyond the Visible: A handbook of best practice in plant UV photobiology (1st ed., p. xxx + 174). Helsinki: University of Helsinki, Department of Biosciences, Division of Plant Biology. ISBN 978-952-10-8363-1 (PDF), 978-952-10-8362-4 (paperback). PDF file available from (http://hdl.handle.net/10138/37558).

Contributing

Pull requests, bug reports, and feature requests are welcome at (https://bitbucket.org/aphalo/ggspectra).

Citation

If you use this package to produce scientific or commercial publications, please cite according to:

citation("ggspectra")
#> 
#> To cite package 'ggspectra' in publications, please use:
#> 
#>   Aphalo, Pedro J. (2015) The r4photobiology suite. UV4Plants
#>   Bulletin, 2015:1, 21-29. DOI:10.19232/uv4pb.2015.1.14
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Article{,
#>     author = {Pedro J. Aphalo},
#>     title = {The r4photobiology suite},
#>     journal = {UV4Plants Bulletin},
#>     volume = {2015},
#>     number = {1},
#>     pages = {21-29},
#>     year = {2015},
#>     doi = {10.19232/uv4pb.2015.1.14},
#>   }

License

© 2015-2018 Pedro J. Aphalo (pedro.aphalo@helsinki.fi). Released under the GPL, version 2 or greater. This software carries no warranty of any kind.

Copy Link

Version

Install

install.packages('ggspectra')

Monthly Downloads

594

Version

0.3.1

License

GPL (>= 2)

Maintainer

Pedro Aphalo

Last Published

October 29th, 2018

Functions in ggspectra (0.3.1)

Tfr_internal_label

Transmittance axis labels
autoplot.generic_spct

Plot a spectrum.
black_or_white

Chose black vs. white color based on weighted mean of RGB channels
ggspectra-package

ggspectra: Extensions to 'ggplot2' for Radiation Spectra
ggplot

Create a new ggplot plot from spectral data.
decoration

Add decorations to spectrum plot (private)
plot.calibration_spct

Plot methods for spectral irradiation calibrations.
geom_spct

Spectral data plots.
plot.cps_spct

Plot method for spectra expressed as detector counts per second.
cal_plot

Plot method for spectral irradiation calibrations.
cps_plot

Plot an instrument counts spectrum.
GeomSpct

Stat* Objects
duration2character

Convert lubridate duration objects to a string if possible
decode_annotations

Merge user supplied annotations with default ones
e_plot

Plot a source spectrum.
counts_label

Raw-counts axis labels
e_rsp_plot

Plot method for response spectra.
cps_label

Counts-per-second axis labels
color_chart

Create a color checker chart
plot.reflector_spct

Plot methods for reflector spectra.
ggtitle_spct

Add title to a spectral plot
raw_plot

Plot method for spectra expressed as raw detector counts.
exponent2prefix

SI unit prefixes
find_idfactor

Find 'idfactor'
plot.filter_spct

Plot methods for filter spectra.
plot.response_spct

Plot methods for response spectra.
multiplot

Multiple plot function
plot.generic_spct

Warn if plot methods is called.
plot.source_spct

Plot methods for light-source spectra.
s.e.response_label

spectral response axis labels
plot.waveband

Plot method for waveband objects.
s.e.irrad_label

spectral irradiance axis labels
scale_x_wl_continuous

Wavelength x-scale
scale_y_Tfr_internal_continuous

Transmittance y-scale
stat_find_qtys

Find quantity value for target wavelength value.
stat_color

Calculate colours from wavelength.
scale_y_A_internal_continuous

Absorbance y-scale
plot.object_spct

Plot method for object spectra.
scale_y_Rfr_specular_continuous

Reflectance y-scale
plot.raw_spct

Plot method for spectra expressed as raw detector counts.
scale_y_s.e.response_continuous

Spectral response y-scale
scale_y_counts_continuous

Raw-counts y-scale
scale_y_cps_continuous

Counts-per-second y-scale
sec_axis_w_number

Secondary axes for wavelengths
stat_find_wls

Find wavelength for target quantity value.
scale_y_s.e.irrad_continuous

Spectral irradiance y-scale
q_plot

Plot a source spectrum.
stat_wb_label

Label ranges under spectral curve.
q_rsp_plot

Plot a response spectrum.
stat_wb_mean

Integrate ranges under curve.
stat_wl_summary

Average area under curve for regions.
stat_label_peaks

Label peaks and valleys.
stat_wb_hbar

Integrate ranges under curve.
stat_wb_irrad

Integrate irradiance for wavebands.
stat_peaks

Find peaks and valleys.
stat_wb_total

Integrate ranges under spectral curve.
w_number

Wavelength conversions
stat_wb_box

Draw colour boxes for wavebands
subtitle_spct.generic_spct

Build a plot subtitle from object metadata (deprecated!)
stat_wl_strip

Calculate colours from wavelength.
title_spct

Build a plot title from object metadata (deprecated!)
w_length_label

Wave- axis labels
stat_wb_column

Integrate ranges under curve.
stat_wb_contribution

Integrate ranges under spectral curve.
stat_wb_relative

Integrate ranges under spectral curve.
stat_wb_sirrad

Integrate spectral irradiance for wavebands.
Afr_plot

Plot a filter spectrum.
O_plot

Plot an object spectrum
SI_pl_format

Formatter for plain labels discounting for SI multipliers
SI_tg_format

Formatter for tagged labels using SI multipliers
A_internal_label

Absorbance axis labels
A_plot

Plot a filter spectrum.
T_plot

Plot a filter spectrum.
Rfr_specular_label

Reflectance axis labels
R_plot

Plot a reflector spectrum