graph_ma | R Documentation |
Function returns either an overlapped or multi-paneled plot of the observed time series, along with the plot for the moving average. The actual moving average values are also returned in a data.frame.
graph_ma(
df = NULL,
time_col = NULL,
value_col = NULL,
window_n = 4,
ma_type = "sma",
overlap = TRUE,
title = NULL,
ma_caption = NULL,
ob_caption = NULL,
x_title = NULL,
y_title = NULL,
x_limits = NULL,
x_major_breaks = waiver(),
x_major_date_breaks = waiver(),
x_date_labels = waiver(),
y_limits = NULL,
y_major_breaks = waiver(),
show_major_grids = TRUE,
show_minor_grids = TRUE,
show_pts = TRUE,
show_observe = TRUE,
col_width = 18,
row_height = 5,
display_plot = TRUE,
png_file_path = NULL
)
df |
A data frame with variables for times and corresponding values. |
time_col |
Names the column from |
value_col |
Names the value column from |
window_n |
An integer that controls the backward window length of the moving average. |
ma_type |
A string that sets the type of moving average. Accepted values are "sma" simple, "tri" triangular, "wma" weighted, "exp" exponential, "mod" modified, and "spe" Spencer weighted 15 point average. |
overlap |
A logical which if |
title |
A string that sets the overall title to the plots. |
ma_caption |
A string that sets the caption for the ma plot. |
ob_caption |
A string that sets the caption for the observed plot. |
x_title |
A string that defines the x axis title. |
y_title |
A string that defines the y axis title. |
x_limits |
A Date/POSIXct 2 element vector that sets the minimum and maximum for the x axis. Use NA to refer to the existing minimum and maximum. |
x_major_breaks |
A Date/POSIXct vector or function that defines the exact major tic locations along the x axis. |
x_major_date_breaks |
For Date/POSIXct, a string containing the number and date unit for major breaks.
Examples: |
x_date_labels |
For Date/POSIXct, a string containing the format codes for the x axis date format.
This can be a strftime format for each x axis tic date label.
Examples: |
y_limits |
A numeric 2 element vector that sets the minimum and maximum for the y axis.
The default is |
y_major_breaks |
A numeric vector or function that defines the exact major tic locations for the moving average y axis'. |
show_major_grids |
A logical that controls the appearance of major grids. |
show_minor_grids |
A logical that controls the appearance of minor grids. |
show_pts |
A logical which if FALSE will plot only the lines. |
show_observe |
A logical that controls the appearance of the observed time series. |
col_width |
An numeric that sets the width of each plot in centimeters. |
row_height |
A numeric that sets the height of each plot in centimeters. |
display_plot |
A logical that if TRUE displays the plot. |
png_file_path |
A character string with the directory and file name to produce a png image of the plot. |
The function uses the RplotterPkg::multi_panel_grid package to draw the multi-paneled plot.
If display_plot
is TRUE then the plots will be displayed. If display_plot
is FALSE then
the function returns a named list that includes a plot object which can be displayed from the console by entering:
grid::grid.newpage()
grid::grid.draw(plot object)
Returning a named list with:
"ma_df" – A data.frame/data.table with column variables for time "DateTime" and the moving average values "Value" and source of the values "Source".
"plots" – A multi-panelled/overlapped TableGrob object plotting the observed series and the moving averages.
Use grid::grid.draw(plots)
to display the plots.
Rick Dean
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.