A custom ggplot2 extension to shade areas in a plot according to provided light hours.
It shades from lights off to lights on. Usage through
geom_lights()
or stat_ligths()
By default, shading is clipped to the actual range of the data to avoid misleading over-extension.
Setting clip_to_data = FALSE
causes shading to fill the panel (via -Inf/Inf), which can be useful
but may behave unexpectedly if you manually set axis limits.
Arguments
- lights_on_hour
An integer representing the hour of the day (0-23) when the lights turn on.
- lights_off_hour
An integer representing the hour of the day (0-23) when the lights turn off.
- fill
A string representing the color of the shading.
- alpha
A numeric representing the transparency of the shading, between 0 (transparent) and 1 (opaque).
- clip_to_data
Logical. If TRUE (default), shading is clipped to the range of the data. If FALSE, shading extends beyond the data using -Inf/Inf. This can create full-panel shading, but may cause unexpected visuals if combined with custom
scale_x_datetime()
limits.