diff --git a/NAMESPACE b/NAMESPACE index c9038dd..3f316be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -29,6 +29,7 @@ export(ax_dataLabels) export(ax_facet_grid) export(ax_facet_wrap) export(ax_fill) +export(ax_forecast_data_points) export(ax_grid) export(ax_labels) export(ax_labels2) diff --git a/NEWS.md b/NEWS.md index 140b42f..b5f61ad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ apexcharter 0.4.1 * Updated ApexCharts.js to 3.40.0 (new chart type: dumbbell chart). * `apex()` : added support for boxplot. +* New function `ax_forecast_data_points()` to mark points as forecasted values. diff --git a/R/apex-utils.R b/R/apex-utils.R index 8785d6e..2d30a6a 100644 --- a/R/apex-utils.R +++ b/R/apex-utils.R @@ -1273,9 +1273,44 @@ ax_nodata <- function(ax, - - - +#' Forecast data points +#' +#' @template ax-default +#' @param count Number of ending data-points you want to indicate as a forecast or prediction values. +#' The ending line/bar will result into a dashed border with a distinct look to differentiate from the rest of the data-points. +#' @param fillOpacity Opacity of the fill attribute. +#' @param strokeWidth Sets the width of the points. +#' @param dashArray Creates dashes in borders of svg path. Higher number creates more space between dashes in the border. +#' @param ... Additional arguments (not used). +#' +#' @export +#' +#' @examples +#' # add 5 predictions to data then plot it +#' data.frame( +#' time = seq_len(53), +#' lh = c( +#' as.vector(lh), +#' as.vector(predict(arima(lh, order = c(1,0,1)), 5)$pred) +#' ) +#' ) %>% +#' apex(aes(time, lh), type = "line") %>% +#' ax_xaxis(type = "numeric") %>% +#' ax_forecast_data_points(count = 5) +ax_forecast_data_points <- function(ax, + count = NULL, + fillOpacity = NULL, + strokeWidth = NULL, + dashArray = NULL, + ...) { + params <- list( + count = count, + fillOpacity = fillOpacity, + strokeWidth = strokeWidth, + dashArray = dashArray + ) + .ax_opt2(ax, "forecastDataPoints", l = dropNulls(params)) +} diff --git a/man/ax_forecast_data_points.Rd b/man/ax_forecast_data_points.Rd new file mode 100644 index 0000000..a5b3765 --- /dev/null +++ b/man/ax_forecast_data_points.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/apex-utils.R +\name{ax_forecast_data_points} +\alias{ax_forecast_data_points} +\title{Forecast data points} +\usage{ +ax_forecast_data_points( + ax, + count = NULL, + fillOpacity = NULL, + strokeWidth = NULL, + dashArray = NULL, + ... +) +} +\arguments{ +\item{ax}{An \code{\link[=apexchart]{apexchart()}} \code{htmlwidget} object.} + +\item{count}{Number of ending data-points you want to indicate as a forecast or prediction values. +The ending line/bar will result into a dashed border with a distinct look to differentiate from the rest of the data-points.} + +\item{fillOpacity}{Opacity of the fill attribute.} + +\item{strokeWidth}{Sets the width of the points.} + +\item{dashArray}{Creates dashes in borders of svg path. Higher number creates more space between dashes in the border.} + +\item{...}{Additional arguments (not used).} +} +\value{ +An \code{\link[=apexchart]{apexchart()}} \code{htmlwidget} object. +} +\description{ +Forecast data points +} +\examples{ +# add 5 predictions to data then plot it +data.frame( + time = seq_len(53), + lh = c( + as.vector(lh), + as.vector(predict(arima(lh, order = c(1,0,1)), 5)$pred) + ) +) \%>\% + apex(aes(time, lh), type = "line") \%>\% + ax_xaxis(type = "numeric") \%>\% + ax_forecast_data_points(count = 5) +}