Secondary axes for wavelength data in nanometres. With suitable scaling and name (axis label) for frequency, wave number, photon energy and wavelength.
Usage
sec_axis_w_number(
unit.exponent = -6,
label.text = axis_labels(append = ifelse(axis.symbols, ",", ""))[["w.number"]],
axis.symbols = getOption("ggspectra.axis.symbols", default = TRUE)
)
sec_axis_w_frequency(
unit.exponent = 12,
label.text = axis_labels(append = ifelse(axis.symbols, ",", ""))[["freq"]],
axis.symbols = getOption("ggspectra.axis.symbols", default = TRUE)
)
sec_axis_energy_eV(
unit.exponent = 0,
label.text = axis_labels(append = ifelse(axis.symbols, ",", ""))[["energy"]],
axis.symbols = getOption("ggspectra.axis.symbols", default = TRUE)
)
sec_axis_energy_J(
unit.exponent = -18,
label.text = axis_labels(append = ifelse(axis.symbols, ",", ""))[["energy"]],
axis.symbols = getOption("ggspectra.axis.symbols", default = TRUE)
)
sec_axis_wl(
unit.exponent = -9,
label.text = axis_labels(append = ifelse(axis.symbols, ",", ""))[["w.length"]],
axis.symbols = getOption("ggspectra.axis.symbols", default = TRUE)
)Details
These secondary axis functions can be used only when the x
aesthetic is mapped to a numerical variable containing wavelength values
expressed in nanometres. They can be used to add a secondary x axis to
plots created using ggplot() or autoplot().
See also
the default text used for quantity names are most easily changed
by resetting all the defaults once as explained in
axis_labels_uk, even if it is possible to override them
also in each call.
Examples
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(sec.axis = sec_axis_w_number())
# Secondary axes can be added to plots built with autoplot() methods
autoplot(sun.spct) +
scale_x_wl_continuous(sec.axis = sec_axis_w_number())
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
# Using 'ggplot2' scale
ggplot(sun.spct) +
geom_line() +
scale_x_continuous(name = w_length_label(),
sec.axis = sec_axis_w_number())
# change scale multipliers, SI defined
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(-6, sec.axis = sec_axis_w_number(-3))
# change scale multipliers, not SI defined (best avoided)
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(-8, sec.axis = sec_axis_w_number(-4))
# Change quantity name to Spanish
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(label.text = "Longitud de onda,",
sec.axis = sec_axis_w_frequency(label.text = "Frecuencia,"))
# Frequency in secondary axis
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(sec.axis = sec_axis_w_frequency())
# Energy (per photon) in atto joules
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(sec.axis = sec_axis_energy_J())
# Energy (per photon) in electron volts
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(sec.axis = sec_axis_energy_eV())
# Secondary axis with wavelength using a different scale factor
ggplot(sun.spct) +
geom_line() +
scale_x_wl_continuous(sec.axis = sec_axis_wl(-6))
# Secondary axes can be added to plots built with autoplot() methods
autoplot(sun.spct) +
scale_x_wl_continuous(sec.axis = sec_axis_wl(-6))
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
