# ggplot() methods for spectral objects set a default mapping for x and y.
ggplot(sun.spct) +
geom_line() +
stat_label_peaks(hjust = "left", span = 31, angle = 90, color = "red")
ggplot(sun.spct) +
geom_line() +
stat_label_valleys(hjust = "right", span = 21, angle = 90, color = "blue")
# using transformed scales requires the user to pass functions as arguments
ggplot(sun.spct) +
geom_line() +
stat_label_peaks(hjust = "left", span = 31, angle = 90, color = "red",
x.label.transform = abs) +
scale_x_reverse()
ggplot(sun.spct) +
geom_line() +
stat_label_peaks(hjust = "left", span = 31, angle = 90, color = "red",
x.label.transform = function(x) {10^x}) +
scale_x_log10()
# geom_label
ggplot(sun.spct) +
geom_line() +
stat_peaks(span = 41, shape = 21, size = 3) +
stat_label_peaks(span = 41, geom = "label", label.fmt = "%3.0f nm") +
scale_fill_identity() +
scale_color_identity() +
expand_limits(y = c(NA, 1))
# using 'ggrepel' to avoid overlaps
# too slow for CRAN checks
if (FALSE) {
library(ggrepel)
ggplot(sun.spct) + geom_line() +
stat_peaks(span = 41, shape = 21, size = 3) +
stat_label_peaks(span = 41, geom = "label_repel", segment.colour = "red",
nudge_y = 0.12, label.fmt = "%3.0f nm",
max.overlaps = Inf, min.segment.length = 0) +
scale_fill_identity() +
scale_color_identity() +
expand_limits(y = c(NA, 1))
}
Run the code above in your browser using DataLab