Learn R Programming

gghourglass (version 0.0.3)

AnnotateDaylight: Annotate ggplot with a band indicating solar events

Description

Annotate a ggplot (currently only plots using coord_hourglass() is supported) with a coloured band indicating solar events, such as sunset and sunrise.

Usage

AnnotateDaylight

annotate_daylight( longitude = 0, latitude = 60, sun_prop = c("sunrise", "sunset"), ... )

Value

Returns a ggplot2::layer() which can be added to a ggplot2::ggplot()

Format

An object of class AnnotateDaylight (inherits from GeomPolygon, Geom, ggproto, gg) of length 6.

Arguments

longitude, latitude

Geographical location that will be used to calculate sunlight times.

sun_prop

A vector of two solar events that should be captured by the annotation. It will be shown as a coloured band between these two events. Default is c("sunrise", "sunset"), but could also be c("dusk", "dawn"). See suncalc::getSunlightTimes() for all allowed solar events.

...

Passed to the list of layer parameters.

Author

Pepijn de Vries

Examples

Run this code
library(ggplot2)
data(bats)

monitoring <- attr(bats, "monitoring")

ggplot(subset(bats, format(RECDATETIME, "%Y") == "2018"),
       aes(x = RECDATETIME, col = SPECDESCSCI)) +
  annotate_daylight(monitoring$longitude[1], monitoring$latitude[1], c("sunset", "sunrise")) +
  annotate_daylight(monitoring$longitude[1], monitoring$latitude[1], c("dusk", "dawn")) +
  geom_hourglass()

Run the code above in your browser using DataLab