# ggplot() methods for spectral objects set a default mapping for x and y.
# PEAKS
ggplot(sun.spct) +
geom_line() +
stat_peaks()
# threshold relative to data range [0..1]
ggplot(sun.spct) +
geom_line() +
stat_peaks(global.threshold = 0.6) # 0.6 * range of data
# threshold in data units
ggplot(sun.spct) +
geom_line() +
stat_peaks(global.threshold = I(0.4))
# threshold in data units
ggplot(sun.spct, unit.out = "photon") +
geom_line() +
stat_peaks(global.threshold = I(2e-6)) # Q in mol m-2 s-1
# VALLEYS
ggplot(sun.spct) +
geom_line() +
stat_valleys()
# discard multiple maxima or minima
ggplot(sun.spct) +
geom_line() +
stat_valleys(strict = TRUE)
# threshold relative to data range [0..1]
ggplot(sun.spct) +
geom_line() +
stat_valleys(global.threshold = 0.6)
# reverse threshold relative to data range [-1..0]
ggplot(sun.spct) +
geom_line() +
stat_valleys(global.threshold = -0.9)
# threshold in data units using I()
ggplot(sun.spct) +
geom_line() +
stat_valleys(global.threshold = I(0.6), strict = TRUE)
# USING OTHER COMPUTED VALUES
# colours matching the wavelength at peaks
ggplot(sun.spct) +
geom_line() +
stat_peaks(span = 51, size = 2.7,
mapping = aes(colour = after_stat(wl.colour))) +
scale_color_identity()
# labels for local maxima
ggplot(sun.spct) +
geom_line() +
stat_peaks(span = 51, geom = "point", colour = "red") +
stat_peaks(span = 51, geom = "text", colour = "red",
vjust = -0.4, label.fmt = "%3.2f nm")
# labels for local fitted peaks
ggplot(sun.spct) +
geom_line() +
stat_peaks(span = 51, geom = "point", colour = "red", refine.wl = TRUE) +
stat_peaks(span = 51, geom = "text", colour = "red",
vjust = -0.4, label.fmt = "%3.2f nm",
refine.wl = TRUE)
# fitted peaks and valleys
ggplot(sun.spct) +
geom_line() +
stat_peaks(span = 31, geom = "point", colour = "red", refine.wl = TRUE) +
stat_peaks(mapping = aes(fill = after_stat(wl.colour), color = after_stat(BW.colour)),
span = 31, geom = "label",
size = 3, vjust = -0.2, label.fmt = "%.4g nm",
refine.wl = TRUE) +
stat_valleys(span = 51, geom = "point", colour = "blue", refine.wl = TRUE) +
stat_valleys(mapping = aes(fill = after_stat(wl.colour), color = after_stat(BW.colour)),
span = 51, geom = "label",
size = 3, vjust = 1.2, label.fmt = "%.4g nm",
refine.wl = TRUE) +
expand_limits(y = 0.85) + # make room for label
scale_fill_identity() +
scale_color_identity()
Run the code above in your browser using DataLab