cavity_split: Split cavity use data by different time frames

View source: R/summary.R

cavity_splitR Documentation

Split cavity use data by different time frames

Description

Split cavity use bouts at midnight, midday, or at sunrise/sunset. The output from cavity_detect is automatically split at midnight.

Usage

cavity_split(
  cavity,
  split = c("midnight", "midday", "riseset"),
  sun = NULL,
  loc = NULL
)

Arguments

cavity

Data frame. Bouts of cavity use, output from cavity_detect.

split

Character. One of "midnight" (default), "midday", or "riseset"

sun

Data frame. Detected sunrise and sunset events, output of sun_detect. Required when split = "riseset".

loc

Numeric vector. Longitude and Latitude of the observations (if not in the data, this must be provided when split = "riseset").

Details

Depending on your area of interest, when summarizing cavity use data, you'll want to collapse cavity use according to different time frames.

  • split = "riseset" Split at sunrise and sunset to separate cavity use during the day from that at night

  • split = "midnight" Split at midnight to separate cavity use between date, focusing on daytime patterns

  • split = "midday" Split at noon to separate cavity use between days, focusing on nighttime patterns. Dates for morning activity are assigned to previous day.

Value

cavity data frame with bouts of cavity use split according to the specification.

Examples


s <- sun_detect(flicker)
e <- cavity_detect(flicker, sun = s)
loc <- c(flicker$lon[1], flicker$lat[1])

e_day <- cavity_split(e, loc, split = "riseset", sun = s)

library(dplyr)
library(tidyr)
library(ggplot2)
e_summary <- e_day %>%
  group_by(side, location) %>%
  summarize(hrs = sum(length_hrs)) %>%
  group_by(side) %>%
  mutate(p = hrs/sum(hrs) * 100) %>%
  complete(location = unique(e$location), fill = list(p = 0))

 ggplot(data = e_summary, aes(x = side, y = p, fill = location)) +
   geom_bar(stat = "identity") +
   labs(x = "Time of day", y = "% time spent")


steffilazerte/cavityuse documentation built on Aug. 4, 2022, 11:22 p.m.