ggplot()
initializes a ggplot object. It can be used to declare the
input spectral object for a graphic and to optionally specify the set of plot
aesthetics intended to be common throughout all subsequent layers unless
specifically overridden.
# S3 method for source_spct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
environment = parent.frame()
)# S3 method for response_spct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
environment = parent.frame()
)
# S3 method for filter_spct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
plot.qty = getOption("photobiology.filter.qty", default = "transmittance"),
environment = parent.frame()
)
# S3 method for reflector_spct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
plot.qty = NULL,
environment = parent.frame()
)
# S3 method for cps_spct
ggplot(data, mapping = NULL, ..., range = NULL, environment = parent.frame())
# S3 method for calibration_spct
ggplot(data, mapping = NULL, ..., range = NULL, environment = parent.frame())
# S3 method for raw_spct
ggplot(data, mapping = NULL, ..., range = NULL, environment = parent.frame())
# S3 method for object_spct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
plot.qty = getOption("photobiology.object.qty", default = "all"),
environment = parent.frame()
)
# S3 method for generic_spct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
spct_class,
environment = parent.frame()
)
# S3 method for generic_mspct
ggplot(data, mapping = NULL, ..., range = NULL, environment = parent.frame())
# S3 method for filter_mspct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
plot.qty = getOption("photobiology.filter.qty", default = "transmittance"),
environment = parent.frame()
)
# S3 method for source_mspct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
unit.out = getOption("photobiology.radiation.unit", default = "energy"),
environment = parent.frame()
)
# S3 method for object_mspct
ggplot(
data,
mapping = NULL,
...,
range = NULL,
plot.qty = getOption("photobiology.object.qty", default = ifelse(length(data) > 1L,
"as.is", "all")),
environment = parent.frame()
)
Default spectrum dataset to use for plot. If not a spectrum, the
methods used will be those defined in package ggplot2
. See
ggplot
. If not specified, must be supplied in each
layer added to the plot.
Default list of aesthetic mappings to use for plot. If not specified, in the case of spectral objects, a default mapping will be used.
Other arguments passed on to methods.
an R object on which range() returns a vector of length 2, with min and max wavelengths (nm).
character string indicating type of units to use for
plotting spectral irradiance or spectral response, "photon"
or
"energy"
.
If a variable defined in the aesthetic mapping is not
found in the data, ggplot will look for it in this environment. It defaults
to using the environment in which ggplot()
is called.
character string One of "transmittance"
,
"absorptance"
or "absorbance"
for filter_spct
objects,
and in addition to these "reflectance"
, "all"
or
"as.is"
for object_spct
objects.
character Class into which a generic_spct
object
will be converted before plotting. The column names in data should
match those expected by the class constructor (see
setGenericSpct
); other arguments should be
passed by name).
In the case of class object_spct, the arguments
"all"
and "as.is"
if passed to plot.qty
, indicate in
the first case that the data are to be converted into long form, to allow
stacking, while in the second case data
is copied unchanged to the
plot object. "reflectance"
passed to plot.qty
converts
data
into a replector_spct
object and "absorbance"
,
"absorptance"
and "reflectance"
, convert data
into a
filter_spct
.
The method for collections of spectra
accepts arguments for the same parameters as the corresponding methods for
single spectra. Heterogeneous generic collections of spectra are not
supported. When plotting collections of spectra the factor spct.idx
contains as levels the names of the individual members of the collection,
and can be mapped to aesthetics or used for faceting.
ggplot()
is typically used to construct a plot incrementally, using
the +
operator to add layers to the existing ggplot object. This is
advantageous in that the code is explicit about which layers are added and
the order in which they are added. For complex graphics with multiple layers,
initialization with ggplot
is recommended.
We show seven common ways to invoke ggplot
for spectra and
collections of spectra:
ggplot(spct)
ggplot(spct, unit.out = <unit.to.use>)
ggplot(spct, plot.qty = <quantity.to.plot>)
ggplot(spct, range = <wavelength.range>)
ggplot(spct) + aes(<other aesthetics>)
ggplot(spct, aes(x, y, <other aesthetics>))
ggplot(spct, aes())
The first method is recommended if all layers use the same data and the same set of automatic default x and y aesthetics. The second, third and fourth use automatic default x and y aesthetics but first transform or trim the spectral data to be plotted. The fifth uses automatic default x and y aesthetics and adds mappings for other aesthetics. These patterns can be combined as needed. The sixth disables the use of a default automatic mapping, while the seventh delays the mapping of aesthetics and can be convenient when using different mappings for different geoms.
ggplot(sun.spct) + geom_line()
ggplot(sun.spct, unit.out = "photon") + geom_line()
ggplot(yellow_gel.spct) + geom_line()
ggplot(yellow_gel.spct, plot.qty = "absorbance") + geom_line()
ggplot(Ler_leaf.spct) + facet_grid(~variable) + geom_line()
ggplot(Ler_leaf.spct) + aes(linetype = variable) + geom_line()
Run the code above in your browser using DataLab