time_plot: Time Series Plot with Day/Night Shading

View source: R/15-time_plot.R

time_plotR Documentation

Time Series Plot with Day/Night Shading

Description

This function generates a time series plot using ggplot2 with shaded regions indicating day and night times. It can plot data points, allow for faceting by day, and adjust for time zones.

Usage

time_plot(
  x,
  time,
  color = "blue",
  y_axis_name = "Value",
  sun_rise_time = "6:00:00",
  sun_set_time = "18:00:00",
  time_gap = 12,
  add_point = FALSE,
  facet = FALSE
)

Arguments

x

A numeric vector of values to plot.

time

A POSIXct or POSIXlt object representing the time points of the x values.

color

The color to be used for the lines and points in the plot, defaults to "blue".

y_axis_name

The label for the y-axis, defaults to "Value".

sun_rise_time

A character string representing sunrise time, defaults to "6:00:00".

sun_set_time

A character string representing sunset time, defaults to "18:00:00".

time_gap

The gap in hours for the x-axis breaks, defaults to 12.

add_point

Logical, whether to add points to the line plot, defaults to FALSE.

facet

Logical, whether to facet the plot by day, defaults to FALSE.

Details

This function utilizes the ggplot2, lubridate, and scales packages to create a time series plot. Day and night periods are shaded to distinguish between them visually. Optional faceting by day can be enabled to separate the plot into panels for each day. Additionally, data points can be added to the plot if desired.

Value

A ggplot object that represents the time series plot.

Note

This function assumes that 'base_theme' is a ggplot2 theme object defined elsewhere in the user's environment. Adjust the 'sun_rise_time' and 'sun_set_time' to match the local times for sunrise and sunset.

Author(s)

Xiaotao Shen shenxt1990@outlook.com

Examples

data("step_data", package = "laggedcor")

x = step_data$step
time = step_data$time

time_plot(x, time)

jaspershen/laggedcor documentation built on Nov. 9, 2023, 3:44 p.m.