stat_ld_annotations: Compute and display light/dark annotations onto a plot object

Description Usage Arguments Value References See Also Examples

Description

This function is used to show light and dark (L and D) phases as boxes on top a plot.

Usage

1
2
3
4
5
stat_ld_annotations(mapping = NULL, data = NULL,
  position = "identity", ld_colours = c("white", "black"),
  ypos = "bottom", height = 0.03, period = hours(24), phase = 0,
  l_duration = hours(12), outline = "black", x_limits = c(NA, NA),
  ..., na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

ld_colours

character vector of length two setting the colours for light and dark phases, respectively. The default is c("white", "black").

ypos

position and height of the annotation on the y axis. It can be either "top" or "bottom". The default, "bottom" will put the labels below any data.

height

relative height of the rectangles. The default is 3 percent (0.03).

period, phase, l_duration

period, phase and duration of the L phase (in seconds) of the LD cycle.

outline

colour of the border of the rectangles. A value of NA draws no border.

x_limits

numerical vector of length 2 for the start and end of the annotations (in seconds). The default, c(NA, NA), uses the full range of the plotted data.

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

Value

A ggplot layer.

References

See Also

Other layers: geom_peak, stat_bar_tile_etho, stat_pop_etho

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(behavr)
# We start by making a to dataset with 20 animals
metadata <- data.frame(id = sprintf("toy_experiment | %02d", 1:20),
                   condition = c("A", "B"))
dt <- toy_activity_data(metadata, 3)
# We build a plot object
pl <-  ggetho(dt, aes(y = asleep)) + stat_pop_etho()
pl + stat_ld_annotations()
# We can also put the annotations in the background:
pl <-  ggetho(dt, aes(y = asleep)) +
                 stat_ld_annotations(outline = NA) +
                 stat_pop_etho()
pl
# Different colours (e.g. DD)
pl + stat_ld_annotations(ld_colour = c("grey", "black"))
# Shorter period
pl + stat_ld_annotations(period = hours(22), phase = hours(3))
# On a tile plot:
pl <-  ggetho(dt, aes(z = asleep)) + stat_tile_etho()
pl + stat_ld_annotations()

ggetho documentation built on April 30, 2020, 1:06 a.m.