added ax_forecast_data_points()

This commit is contained in:
pvictor 2023-05-17 15:49:28 +02:00
parent 7705b91e88
commit b7ed86e556
4 changed files with 88 additions and 3 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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))
}

View File

@ -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)
}