Take a vector of Datetimes and return the start of the first and end of the
last day of data. The start and the length can be adjusted by
durations, like lubridate::ddays(). It is used in the gg_days()
function to return a sensible x-axis. This function is a thin wrapper around
lubridate::floor_date() and lubridate::ceiling_date().
Usage
Datetime_limits(
x,
start = NULL,
length = NULL,
unit = "1 day",
midnight.rollover = FALSE,
...
)Arguments
- x
a vector of
Datetimes- start
optional
durationobject, e.g.lubridate::ddays(1)that shifts the start of theDatetimevector by this amount.- length
optional
durationobject, e.g.lubridate::ddays(7)that shifts the end of theDatetimevector by this amount from the (adjusted) start. Depending on the data, you might have to subtract one day from the desired length to get the correct axis-scaling if you start at midnight.- unit
a
characterscalar giving the unit of rounding inlubridate::floor_date()andlubridate::ceiling_date()- midnight.rollover
a
logicalscalar indicating whether to rollover in cases of exact matches of rounded values and input values. Helpful if some cases fall exactly on the rounded values and others don`t.- ...
other arguments passed to
lubridate::floor_date()andlubridate::ceiling_date()
Examples
dataset <- c("2023-08-15", "2023-08-20")
breaks <- Datetime_breaks(dataset)
Datetime_limits(breaks)
#> [1] "2023-08-15 UTC" "2023-08-20 UTC"
Datetime_limits(breaks, start = lubridate::ddays(1))
#> [1] "2023-08-16 UTC" "2023-08-20 UTC"
Datetime_limits(breaks, length = lubridate::ddays(2))
#> [1] "2023-08-15 UTC" "2023-08-18 UTC"
