Skip to contents

[Experimental] 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.

Usage

StatLights

Format

An object of class StatLights (inherits from Stat, ggproto, gg) of length 3.

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.

Value

A ggplot2 layer to be added to a ggplot object.

Examples

if (FALSE) { # \dontrun{
ggplot(df, aes(x = Pi_Time, y = Pellet_Count)) +
  stat_lights(fill = "grey80", alpha = 0.5, lights_on_hour = 7, lights_off_hour = 19) +
  geom_line()

} # }