time_plot | R Documentation |
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.
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
)
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. |
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.
A ggplot object that represents the time series plot.
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.
Xiaotao Shen shenxt1990@outlook.com
data("step_data", package = "laggedcor")
x = step_data$step
time = step_data$time
time_plot(x, time)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.