library(photobiologyWavebands)
# ggplot() methods for spectral objects set a default mapping for x and y.
# Using defaults
ggplot(sun.spct) +
geom_line() +
stat_wb_box(w.band = VIS()) +
stat_wb_contribution(w.band = VIS()) +
scale_fill_identity() + scale_color_identity()
# Setting position and angle of the text
ggplot(sun.spct) +
geom_line() +
stat_wb_box(w.band = VIS_bands()) +
stat_wb_contribution(w.band = VIS_bands(), angle = 90, size = 2.5) +
scale_fill_identity() + scale_color_identity()
# Showing percentages, i.e., using a different format for numbers
ggplot(sun.spct) +
geom_line() +
stat_wb_box(w.band = VIS_bands()) +
stat_wb_contribution(w.band = VIS_bands(), size = 2.5,
label.mult = 100, label.fmt = "%3.0f%%") +
scale_fill_identity() + scale_color_identity()
# Including the name of the waveband, i.e., changing the mapping for label
ggplot(sun.spct, range = c(NA, 410)) +
geom_line() +
stat_wb_box(w.band = UV_bands(), color = "white") +
stat_wb_contribution(w.band = UV_bands(), size = 2.5,
label.mult = 100, label.fmt = "%3.0f%%",
mapping = aes(label = after_stat(paste(wb.name, y.label)))) +
scale_fill_identity() + scale_color_identity()
Run the code above in your browser using DataLab