2018-07-31 22:56:51 +02:00
|
|
|
|
|
|
|
# ApexCharts API ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#' Annotations properties
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-08-01 23:02:29 +02:00
|
|
|
#' @param position Whether to put the annotations behind the charts or in front of it. Available Options: \code{"front"} or \code{"back"}.
|
|
|
|
#' @param yaxis List of lists.
|
|
|
|
#' @param xaxis List of lists.
|
|
|
|
#' @param points List of lists.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
2018-08-01 23:02:29 +02:00
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/annotations/}.
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Horizontal line
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 200),
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_annotations(
|
|
|
|
#' yaxis = list(list(
|
|
|
|
#' y = 11.897,
|
|
|
|
#' borderColor = "firebrick",
|
|
|
|
#' opacity = 1,
|
|
|
|
#' label = list(
|
|
|
|
#' text = "Mean uempmed",
|
|
|
|
#' position = "left",
|
|
|
|
#' textAnchor = "start"
|
|
|
|
#' )
|
|
|
|
#' ))
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' # Vertical line
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 200),
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_annotations(
|
|
|
|
#' xaxis = list(list(
|
|
|
|
#' x = htmlwidgets::JS("new Date('1 Mar 2007').getTime()"),
|
|
|
|
#' strokeDashArray = 0,
|
|
|
|
#' borderColor = "#775DD0",
|
|
|
|
#' label = list(
|
|
|
|
#' text = "A label",
|
|
|
|
#' borderColor = "#775DD0",
|
|
|
|
#' style = list(
|
|
|
|
#' color = "#fff",
|
|
|
|
#' background = "#775DD0"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' ))
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' # Vertical range
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 200),
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_annotations(
|
|
|
|
#' xaxis = list(list(
|
|
|
|
#' x = htmlwidgets::JS("new Date('1 Jan 2009').getTime()"),
|
|
|
|
#' x2 = htmlwidgets::JS("new Date('1 Feb 2010').getTime()"),
|
|
|
|
#' fillColor = "#B3F7CA",
|
|
|
|
#' opacity = 0.4,
|
|
|
|
#' label = list(
|
|
|
|
#' text = "A label",
|
|
|
|
#' borderColor = "#B3F7CA",
|
|
|
|
#' style = list(
|
|
|
|
#' color = "#fff",
|
|
|
|
#' background = "#B3F7CA"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' ))
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' # Point annotation
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 200),
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_annotations(
|
|
|
|
#' points = list(list(
|
|
|
|
#' x = htmlwidgets::JS("new Date('1 Jun 2010').getTime()"),
|
|
|
|
#' y = 25.2,
|
|
|
|
#' marker = list(
|
|
|
|
#' size = 8,
|
|
|
|
#' fillColor = "#fff",
|
|
|
|
#' strokeColor = "red",
|
|
|
|
#' radius = 2
|
|
|
|
#' ),
|
|
|
|
#' label = list(
|
|
|
|
#' text = "Highest",
|
|
|
|
#' offsetY = 0,
|
|
|
|
#' borderColor = "#FF4560",
|
|
|
|
#' style = list(
|
|
|
|
#' color = "#fff",
|
|
|
|
#' background = "#FF4560"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' ))
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_annotations <- function(ax,
|
|
|
|
position = NULL,
|
|
|
|
yaxis = NULL,
|
|
|
|
xaxis = NULL,
|
|
|
|
points = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "annotations", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Chart parameters
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param type Specify the chart type. Available Options: \code{"bar"}, \code{"column"}, \code{"line"},
|
2019-02-17 22:07:04 +01:00
|
|
|
#' \code{"pie"}, \code{"donut"}, \code{"radialBar"}, \code{"scatter"}, \code{"bubble"}, \code{"heatmap"}.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param stacked Logical. Enables stacked option for axis charts.
|
2019-11-26 14:44:59 +01:00
|
|
|
#' @param stackType When stacked, should the stacking be percentage based or normal stacking.
|
|
|
|
#' Available options: \code{"normal"} or \code{"100\%"}.
|
2020-02-28 10:02:01 +01:00
|
|
|
#' @param defaultLocale Locale to use : \code{"ca"}, \code{"de"}, \code{"el"}, \code{"en"}, \code{"es"}, \code{"fi"}, \code{"fr"},
|
|
|
|
#' \code{"hi"}, \code{"hr"}, \code{"hy"}, \code{"id"}, \code{"it"}, \code{"ko"}, \code{"nl"}, \code{"pt-br"},
|
|
|
|
#' \code{"ru"}, \code{"se"}, \code{"tr"}, \code{"ua"}.
|
2019-11-27 23:17:23 +01:00
|
|
|
#' @param locales Array of custom locales parameters.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param animations A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param background Background color for the chart area. If you want to set background with css, use \code{.apexcharts-canvas} to set it.
|
|
|
|
#' @param foreColor Sets the text color for the chart. Defaults to \code{#373d3f}.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param dropShadow A list of parameters. See \url{https://apexcharts.com/docs/options/chart/dropshadow/}.
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @param events See \code{\link{events_opts}}.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param offsetX Sets the left offset for chart.
|
|
|
|
#' @param offsetY Sets the top offset for chart.
|
|
|
|
#' @param selection A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param sparkline List. Sparkline hides all the elements of the charts other than the primary paths. Helps to visualize data in small areas. .
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param toolbar A list of parameters. See \url{https://apexcharts.com/docs/options/chart/toolbar/}.
|
|
|
|
#' @param zoom A list of parameters. See \url{https://apexcharts.com/docs/options/chart/zoom/}.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param width Width of the chart.
|
|
|
|
#' @param height Height of the chart.
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
2019-11-26 14:44:59 +01:00
|
|
|
#' @example examples/ax_chart.R
|
|
|
|
#' @example examples/localization.R
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_chart <- function(ax,
|
|
|
|
type = NULL,
|
|
|
|
stacked = NULL,
|
|
|
|
stackType = NULL,
|
2019-11-26 14:44:59 +01:00
|
|
|
defaultLocale = NULL,
|
|
|
|
locales = NULL,
|
2018-07-31 22:56:51 +02:00
|
|
|
animations = NULL,
|
|
|
|
background = NULL,
|
|
|
|
foreColor = NULL,
|
|
|
|
dropShadow = NULL,
|
|
|
|
events = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
selection = NULL,
|
|
|
|
sparkline = NULL,
|
|
|
|
toolbar = NULL,
|
|
|
|
zoom = NULL,
|
|
|
|
width = NULL,
|
|
|
|
height = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "chart", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Specific options for chart
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2019-02-17 22:07:04 +01:00
|
|
|
#' @param bar See \code{\link{bar_opts}}.
|
|
|
|
#' @param heatmap See \code{\link{heatmap_opts}}.
|
|
|
|
#' @param radialBar See \code{\link{radialBar_opts}}.
|
|
|
|
#' @param pie See \code{\link{pie_opts}}.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("diamonds", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Stack bar type
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut),
|
|
|
|
#' mapping = aes(x = cut, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_plotOptions(
|
|
|
|
#' bar = bar_opts(endingShape = "rounded", columnWidth = "10%")
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#' # Pie
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut),
|
|
|
|
#' mapping = aes(x = cut, y = n),
|
|
|
|
#' type = "pie"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_plotOptions(
|
|
|
|
#' pie = pie_opts(customScale = 0.5)
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' # Radial
|
|
|
|
#' apexchart() %>%
|
|
|
|
#' ax_chart(type = "radialBar") %>%
|
|
|
|
#' ax_plotOptions(
|
|
|
|
#' radialBar = radialBar_opts(
|
|
|
|
#' hollow = list(size = "70%")
|
|
|
|
#' )
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_series(70) %>%
|
|
|
|
#' ax_labels("Indicator")
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_plotOptions <- function(ax,
|
|
|
|
bar = NULL,
|
|
|
|
heatmap = NULL,
|
|
|
|
radialBar = NULL,
|
|
|
|
pie = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "plotOptions", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Colors
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2020-02-14 18:13:24 +01:00
|
|
|
#' @param ... Colors for the chart's series. When all colors are used, it starts from the beginning.
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2018-09-03 23:52:53 +02:00
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/colors/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#'
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("diamonds", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Change default color(s)
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut),
|
|
|
|
#' mapping = aes(x = cut, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_colors("#F7D358")
|
|
|
|
#'
|
|
|
|
#'
|
2019-11-26 10:34:01 +01:00
|
|
|
#' library(scales)
|
2019-06-24 15:18:38 +02:00
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut, color),
|
|
|
|
#' mapping = aes(x = cut, y = n, fill = color)
|
|
|
|
#' ) %>%
|
2019-11-26 10:34:01 +01:00
|
|
|
#' ax_colors(brewer_pal(palette = "Set2")(7))
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_colors <- function(ax, ...) {
|
2019-03-13 09:21:03 +01:00
|
|
|
args <- list(...)
|
|
|
|
if (length(args) == 1) {
|
|
|
|
args <- as.list(args[[1]])
|
|
|
|
}
|
|
|
|
.ax_opt2(ax, "colors", l = args)
|
2018-07-31 22:56:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Labels on data
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param enabled To determine whether to show dataLabels or not.
|
2020-02-14 18:13:24 +01:00
|
|
|
#' @param textAnchor The alignment of text relative to dataLabel's drawing position.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' Accepted values \code{"start"}, \code{"middle"} or \code{"end"}.
|
|
|
|
#' @param offsetX Sets the left offset for dataLabels.
|
|
|
|
#' @param offsetY Sets the top offset for dataLabels.
|
|
|
|
#' @param style A list of parameters.
|
|
|
|
#' @param dropShadow A list of parameters.
|
|
|
|
#' @param formatter The formatter function takes in a single value and allows you to format the value before displaying
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2018-09-03 23:52:53 +02:00
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/datalabels/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("diamonds", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Add data labels
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut),
|
|
|
|
#' mapping = aes(x = cut, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_dataLabels(enabled = TRUE)
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_dataLabels <- function(ax,
|
|
|
|
enabled = NULL,
|
|
|
|
textAnchor = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
style = NULL,
|
|
|
|
dropShadow = NULL,
|
2018-09-03 23:52:53 +02:00
|
|
|
formatter = NULL,
|
2018-07-31 22:56:51 +02:00
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "dataLabels", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Fill property
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param type Whether to fill the paths with solid colors or gradient.
|
|
|
|
#' Available options: \code{"solid"}, \code{"gradient"}, \code{"pattern"} or \code{"image"}.
|
|
|
|
#' @param colors Colors to fill the svg paths..
|
|
|
|
#' @param opacity Opacity of the fill attribute.
|
|
|
|
#' @param gradient A list of parameters.
|
|
|
|
#' @param image A list of parameters.
|
|
|
|
#' @param pattern A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2018-09-03 23:52:53 +02:00
|
|
|
#'
|
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/fill/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("diamonds", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Use a pattern to fill bars
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut, color),
|
|
|
|
#' mapping = aes(x = color, y = n, fill = cut)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_fill(
|
|
|
|
#' type = "pattern",
|
|
|
|
#' opacity = 1,
|
|
|
|
#' pattern = list(
|
|
|
|
#' style = c("circles", "slantedLines", "verticalLines", "horizontalLines", "squares")
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Customise gradient
|
|
|
|
#' apex(
|
|
|
|
#' data = economics,
|
|
|
|
#' mapping = aes(x = date, y = psavert),
|
|
|
|
#' type = "area"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_fill(gradient = list(
|
|
|
|
#' enabled = TRUE,
|
|
|
|
#' shadeIntensity = 1,
|
|
|
|
#' inverseColors = FALSE,
|
|
|
|
#' opacityFrom = 0,
|
|
|
|
#' opacityTo = 1,
|
|
|
|
#' stops = c(0, 2000)
|
|
|
|
#' ))
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_fill <- function(ax,
|
|
|
|
type = NULL,
|
|
|
|
colors = NULL,
|
|
|
|
opacity = NULL,
|
|
|
|
gradient = NULL,
|
|
|
|
image = NULL,
|
|
|
|
pattern = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "fill", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Add grids on chart
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param show Logical. To show or hide grid area (including xaxis / yaxis)
|
|
|
|
#' @param borderColor Colors of grid borders / lines.
|
|
|
|
#' @param strokeDashArray Creates dashes in borders of svg path. Higher number creates more space between dashes in the border.
|
|
|
|
#' @param position Whether to place grid behind chart paths of in front. Available options for position: \code{"front"} or \code{"back"}
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param xaxis A list of parameters.
|
|
|
|
#' @param yaxis A list of parameters.
|
|
|
|
#' @param row A list of parameters.
|
|
|
|
#' @param column A list of parameters.
|
|
|
|
#' @param padding A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/grid/}
|
|
|
|
#'
|
2019-06-24 15:18:38 +02:00
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Hide Y-axis and gridelines
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_grid(show = FALSE)
|
|
|
|
#'
|
|
|
|
#' # just grid lines
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_grid(yaxis = list(lines = list(show = FALSE)))
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' # both x & y
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics,
|
|
|
|
#' mapping = aes(x = date, y = psavert),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_grid(
|
|
|
|
#' yaxis = list(lines = list(show = TRUE)),
|
|
|
|
#' xaxis = list(lines = list(show = TRUE))
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_grid <- function(ax,
|
|
|
|
show = NULL,
|
|
|
|
borderColor = NULL,
|
|
|
|
strokeDashArray = NULL,
|
|
|
|
position = NULL,
|
|
|
|
xaxis = NULL,
|
|
|
|
yaxis = NULL,
|
|
|
|
row = NULL,
|
|
|
|
column = NULL,
|
|
|
|
padding = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "grid", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Alternative axis labels
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-11-06 09:04:16 +01:00
|
|
|
#' @param labels A vector to use as labels.
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param ... Vector. In Axis Charts (line / column), labels can be set instead of setting xaxis categories
|
|
|
|
#' option. While, in pie/donut charts, each label corresponds to value in series array.
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2018-11-06 09:04:16 +01:00
|
|
|
#'
|
|
|
|
#' @name ax_labels
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/labels/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' apexchart() %>%
|
|
|
|
#' ax_chart(type = "pie") %>%
|
|
|
|
#' ax_series(23, 45, 56) %>%
|
|
|
|
#' ax_labels("A", "B", "C")
|
|
|
|
#'
|
|
|
|
#' # same as
|
|
|
|
#' apexchart() %>%
|
|
|
|
#' ax_chart(type = "pie") %>%
|
|
|
|
#' ax_series2(c(23, 45, 56)) %>%
|
|
|
|
#' ax_labels2(c("A", "B", "C"))
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_labels <- function(ax, ...) {
|
|
|
|
.ax_opt(ax, "labels", ...)
|
|
|
|
}
|
2018-11-06 09:04:16 +01:00
|
|
|
#' @rdname ax_labels
|
|
|
|
#' @export
|
|
|
|
ax_labels2 <- function(ax, labels) {
|
|
|
|
.ax_opt2(ax, "labels", l = labels)
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:56:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
#' Legend properties
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param show Logical. Whether to show or hide the legend container.
|
|
|
|
#' @param position Available position options for legend: \code{"top"}, \code{"right"}, \code{"bottom"}, \code{"left"}.
|
2019-06-24 15:18:38 +02:00
|
|
|
#' @param showForSingleSeries Show legend even if there is just 1 series.
|
2020-02-14 18:13:24 +01:00
|
|
|
#' @param showForNullSeries Allows you to hide a particular legend if it's series contains all null values.
|
|
|
|
#' @param showForZeroSeries Allows you to hide a particular legend if it's series contains all 0 values.
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param horizontalAlign Available options for horizontal alignment: \code{"right"}, \code{"center"}, \code{"left"}.
|
|
|
|
#' @param fontSize Sets the fontSize of legend text elements
|
2020-02-14 18:13:24 +01:00
|
|
|
#' @param textAnchor The alignment of text relative to legend's drawing position
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param offsetY Sets the top offset for legend container.
|
|
|
|
#' @param offsetX Sets the left offset for legend container.
|
|
|
|
#' @param formatter JS function. A custom formatter function to append additional text to the legend series names.
|
|
|
|
#' @param labels List with two items \code{"foreColor"} (Custom text color for legend labels)
|
|
|
|
#' and \code{"useSeriesColors"} (Logical, whether to use primary colors or not)
|
|
|
|
#' @param markers List.
|
|
|
|
#' @param itemMargin List with two items \code{"horizontal"} (Horizontal margin for individual legend item)
|
|
|
|
#' and \code{"vertical"} (Vertical margin for individual legend item).
|
|
|
|
#' @param containerMargin List with two items \code{"top"} (Top margin for the whole legend container)
|
|
|
|
#' and \code{"left"} (Left margin for the whole legend container).
|
|
|
|
#' @param onItemClick List with item \code{"toggleDataSeries"}, logical,
|
|
|
|
#' when clicked on legend item, it will toggle the visibility of the series in chart.
|
|
|
|
#' @param onItemHover List with item \code{"highlightDataSeries"}, logical,
|
|
|
|
#' when hovered on legend item, it will highlight the paths of the hovered series in chart.
|
|
|
|
#' @param floating Logical. The floating option will take out the legend from the chart area and make it float above the chart.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/legend/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Legend position
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer, year),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_legend(position = "right")
|
|
|
|
#'
|
|
|
|
#' # hide legend
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer, year),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_legend(show = FALSE)
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_legend <- function(ax,
|
|
|
|
show = NULL,
|
|
|
|
position = NULL,
|
2019-06-24 15:18:38 +02:00
|
|
|
showForSingleSeries = NULL,
|
|
|
|
showForNullSeries= NULL,
|
|
|
|
showForZeroSeries = NULL,
|
2018-09-03 23:52:53 +02:00
|
|
|
horizontalAlign = NULL,
|
2018-07-31 22:56:51 +02:00
|
|
|
fontSize = NULL,
|
|
|
|
textAnchor = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
formatter = NULL,
|
|
|
|
labels = NULL,
|
|
|
|
markers = NULL,
|
|
|
|
itemMargin = NULL,
|
|
|
|
containerMargin = NULL,
|
|
|
|
onItemClick = NULL,
|
|
|
|
onItemHover = NULL,
|
2018-07-31 23:24:35 +02:00
|
|
|
floating = NULL,
|
2018-07-31 22:56:51 +02:00
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "legend", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Markers properties
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-08-01 23:02:29 +02:00
|
|
|
#' @param size Numeric. Size of the marker point.
|
|
|
|
#' @param colors Sets the fill color(s) of the marker point.
|
|
|
|
#' @param strokeColor Stroke Color of the marker.
|
|
|
|
#' @param strokeWidth Stroke Size of the marker.
|
|
|
|
#' @param strokeOpacity Opacity of the border around marker.
|
|
|
|
#' @param fillOpacity Opacity of the marker fill color.
|
|
|
|
#' @param shape Shape of the marker. Available Options for shape: \code{"square"} or \code{"circle"}.
|
|
|
|
#' @param radius Numeric. Radius of the marker (applies to square shape)
|
|
|
|
#' @param offsetX Numeric. Sets the left offset of the marker.
|
|
|
|
#' @param offsetY Numeric. Sets the top offset of the marker.
|
|
|
|
#' @param hover List with item \code{size} (Size of the marker when it is active).
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/markers/}
|
|
|
|
#'
|
2019-06-24 15:18:38 +02:00
|
|
|
#' @examples
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # show points
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 20),
|
|
|
|
#' type = "line",
|
|
|
|
#' mapping = aes(x = date, y = uempmed)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_markers(size = 6)
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_markers <- function(ax,
|
|
|
|
size = NULL,
|
|
|
|
colors = NULL,
|
|
|
|
strokeColor = NULL,
|
|
|
|
strokeWidth = NULL,
|
|
|
|
strokeOpacity = NULL,
|
|
|
|
fillOpacity = NULL,
|
|
|
|
shape = NULL,
|
|
|
|
radius = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
hover = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "markers", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
2019-06-24 15:18:38 +02:00
|
|
|
|
2018-07-31 22:56:51 +02:00
|
|
|
#' No data specification
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param text
|
|
|
|
#' @param align
|
|
|
|
#' @param verticalAlign
|
|
|
|
#' @param offsetX
|
|
|
|
#' @param offsetY
|
|
|
|
#' @param style
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @noRd
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
ax_noData <- function(ax,
|
|
|
|
text = NULL,
|
|
|
|
align = NULL,
|
|
|
|
verticalAlign = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
style = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "noData", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Responsive options
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param ... Additional parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/responsive/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Open in browser and resize window
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer, year),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n, fill = year),
|
|
|
|
#' type = "bar"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_legend(position = "right") %>%
|
|
|
|
#' ax_responsive(
|
|
|
|
#' list(
|
|
|
|
#' breakpoint = 1000,
|
|
|
|
#' options = list(
|
|
|
|
#' plotOptions = list(
|
|
|
|
#' bar = list(
|
|
|
|
#' horizontal = FALSE
|
|
|
|
#' )
|
|
|
|
#' ),
|
|
|
|
#' legend = list(
|
|
|
|
#' position = "bottom"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_responsive <- function(ax, ...) {
|
|
|
|
.ax_opt(ax, "responsive", ...)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Add data to a chart
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param ... Lists containing data to plot, typically list with two items: \code{name} and \code{data}.
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
2018-09-04 00:21:21 +02:00
|
|
|
#'
|
|
|
|
#' @name ax-series
|
2018-07-31 22:56:51 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
2018-08-01 23:02:29 +02:00
|
|
|
#'
|
|
|
|
#' # One serie
|
2019-02-15 22:33:14 +01:00
|
|
|
#' apexchart() %>%
|
2018-08-01 23:02:29 +02:00
|
|
|
#' ax_series(list(
|
|
|
|
#' name = "rnorm",
|
|
|
|
#' data = rnorm(10)
|
|
|
|
#' ))
|
|
|
|
#'
|
|
|
|
#' # Two series
|
2019-02-15 22:33:14 +01:00
|
|
|
#' apexchart() %>%
|
2018-08-01 23:02:29 +02:00
|
|
|
#' ax_series(
|
|
|
|
#' list(
|
|
|
|
#' name = "rnorm 1",
|
|
|
|
#' data = rnorm(10)
|
|
|
|
#' ),
|
|
|
|
#' list(
|
|
|
|
#' name = "rnorm 2",
|
|
|
|
#' data = rnorm(10)
|
|
|
|
#' )
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_series <- function(ax, ...) {
|
|
|
|
.ax_opt(ax, "series", ...)
|
|
|
|
}
|
|
|
|
|
2018-09-04 00:21:21 +02:00
|
|
|
#' @param l A list.
|
|
|
|
#' @export
|
|
|
|
#' @rdname ax-series
|
|
|
|
ax_series2 <- function(ax, l) {
|
|
|
|
.ax_opt2(ax, "series", l)
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:56:51 +02:00
|
|
|
|
|
|
|
#' Charts' states
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param normal A list of parameters.
|
|
|
|
#' @param hover A list of parameters.
|
|
|
|
#' @param active A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/states/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Inverse effect on hover
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n),
|
|
|
|
#' type = "bar"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_states(
|
|
|
|
#' hover = list(
|
|
|
|
#' filter = list(
|
|
|
|
#' type = "darken"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_states <- function(ax,
|
|
|
|
normal = NULL,
|
|
|
|
hover = NULL,
|
|
|
|
active = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "states", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Chart's title
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param text Text to display as a title of chart.
|
|
|
|
#' @param align Alignment of subtitle relative to chart area. Possible Options: \code{"left"}, \code{"center"} and \code{"right"}.
|
|
|
|
#' @param margin Numeric. Vertical spacing around the title text.
|
|
|
|
#' @param offsetX Numeric. Sets the left offset for subtitle text.
|
|
|
|
#' @param offsetY Numeric. Sets the top offset for subtitle text
|
|
|
|
#' @param floating Logical. The floating option will take out the subtitle text from the chart area and make it float on top of the chart.
|
|
|
|
#' @param style List with two items: \code{fontSize} (Font Size of the title text) and \code{color} (Fore color of the title text).
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/title/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics,
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_title(
|
|
|
|
#' text = "Median duration of unemployment, in weeks"
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_title <- function(ax,
|
|
|
|
text = NULL,
|
|
|
|
align = NULL,
|
|
|
|
margin = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
floating = NULL,
|
|
|
|
style = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "title", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Chart's subtitle
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param text Text to display as a subtitle of chart.
|
|
|
|
#' @param align Alignment of subtitle relative to chart area. Possible Options: \code{"left"}, \code{"center"} and \code{"right"}.
|
|
|
|
#' @param margin Numeric. Vertical spacing around the subtitle text.
|
|
|
|
#' @param offsetX Numeric. Sets the left offset for subtitle text.
|
|
|
|
#' @param offsetY Numeric. Sets the top offset for subtitle text
|
|
|
|
#' @param floating Logical. The floating option will take out the subtitle text from the chart area and make it float on top of the chart.
|
2018-07-31 23:24:35 +02:00
|
|
|
#' @param style List with two items: \code{fontSize} (Font Size of the subtitle text) and \code{color} (Fore color of the subtitle text).
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/subtitle/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics,
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_title(
|
|
|
|
#' text = "Median duration of unemployment"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_subtitle(
|
|
|
|
#' text = "in weeks"
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_subtitle <- function(ax,
|
|
|
|
text = NULL,
|
|
|
|
align = NULL,
|
|
|
|
margin = NULL,
|
|
|
|
offsetX = NULL,
|
|
|
|
offsetY = NULL,
|
|
|
|
floating = NULL,
|
|
|
|
style = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "subtitle", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Stroke properties
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param show Logical. To show or hide path-stroke / line
|
|
|
|
#' @param curve In line / area charts, whether to draw smooth lines or straight lines.
|
|
|
|
#' Available Options: \code{"smooth"} (connects the points in a curve fashion. Also known as spline)
|
|
|
|
#' and \code{"straight"} (connect the points in straight lines.).
|
|
|
|
#' @param lineCap For setting the starting and ending points of stroke. Available Options:
|
|
|
|
#' \code{"butt"} (ends the stroke with a 90-degree angle), \code{"square"}
|
|
|
|
#' (similar to butt except that it extends the stroke beyond the length of the path)
|
|
|
|
#' and \code{"round"} (ends the path-stroke with a radius that smooths out the start and end points)
|
|
|
|
#' @param width Sets the width of border for svg path.
|
|
|
|
#' @param colors Colors to fill the border for paths.
|
|
|
|
#' @param dashArray Creates dashes in borders of svg path. Higher number creates more space between dashes in the border.
|
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/stroke/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics,
|
|
|
|
#' mapping = aes(x = date, y = uempmed),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_stroke(
|
|
|
|
#' width = 1,
|
|
|
|
#' dashArray = 4
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#' data("economics_long", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics_long,
|
|
|
|
#' mapping = aes(x = date, y = value01, group = variable),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_stroke(
|
|
|
|
#' width = c(1, 2, 3, 4, 5),
|
|
|
|
#' dashArray = c(1, 2, 3, 4, 5)
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_stroke <- function(ax,
|
|
|
|
show = NULL,
|
|
|
|
curve = NULL,
|
|
|
|
lineCap = NULL,
|
|
|
|
width = NULL,
|
|
|
|
colors = NULL,
|
|
|
|
dashArray = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "stroke", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Tooltip options
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param enabled Logical. Show tooltip when user hovers over chart area.
|
|
|
|
#' @param shared Logical. When having multiple series, show a shared tooltip.
|
2020-02-14 18:13:24 +01:00
|
|
|
#' @param followCursor Logical. Follow user's cursor position instead of putting tooltip on actual data points.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param intersect Logical. Show tooltip only when user hovers exactly over datapoint.
|
|
|
|
#' @param inverseOrder Logical. In multiple series, when having shared tooltip, inverse the order of series (for better comparison in stacked charts).
|
|
|
|
#' @param custom JS function. Draw a custom html tooltip instead of the default one based on the values provided in the function arguments.
|
|
|
|
#' @param fillSeriesColor Logical. When enabled, fill the tooltip background with the corresponding series color.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param onDatasetHover A list of parameters.
|
|
|
|
#' @param theme A list of parameters.
|
|
|
|
#' @param x A list of parameters.
|
|
|
|
#' @param y A list of parameters.
|
|
|
|
#' @param z A list of parameters.
|
|
|
|
#' @param marker A list of parameters.
|
|
|
|
#' @param items A list of parameters.
|
|
|
|
#' @param fixed A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/tooltip/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Hide tooltip
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer, year),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_tooltip(enabled = FALSE)
|
|
|
|
#'
|
|
|
|
#' # Share between series
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer, year),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_tooltip(shared = TRUE)
|
|
|
|
#'
|
|
|
|
#' # Fixed tooltip
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics,
|
|
|
|
#' mapping = aes(x = date, y = psavert),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_tooltip(
|
|
|
|
#' fixed = list(enabled = TRUE, position = "topLeft")
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_tooltip <- function(ax,
|
|
|
|
enabled = NULL,
|
|
|
|
shared = NULL,
|
|
|
|
followCursor = NULL,
|
|
|
|
intersect = NULL,
|
|
|
|
inverseOrder = NULL,
|
|
|
|
custom = NULL,
|
|
|
|
fillSeriesColor = NULL,
|
|
|
|
onDatasetHover = NULL,
|
|
|
|
theme = NULL,
|
|
|
|
x = NULL,
|
|
|
|
y = NULL,
|
|
|
|
z = NULL,
|
|
|
|
marker = NULL,
|
|
|
|
items = NULL,
|
|
|
|
fixed = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "tooltip", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' X-axis options
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param type Character. Available Options : \code{"categories"} and \code{"datetime"}.
|
|
|
|
#' @param categories Categories are labels which are displayed on the x-axis.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param labels A list of parameters.
|
|
|
|
#' @param axisBorder A list of parameters.
|
|
|
|
#' @param axisTicks A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param tickAmount Number of Tick Intervals to show.
|
|
|
|
#' @param min Lowest number to be set for the x-axis. The graph drawing beyond this number will be clipped off.
|
|
|
|
#' @param max Highest number to be set for the x-axis. The graph drawing beyond this number will be clipped off.
|
|
|
|
#' @param range Range takes the max value of x-axis, subtracts the provided range value and gets the min value based on that.
|
|
|
|
#' So, technically it helps to keep the same range when min and max values gets updated dynamically.
|
|
|
|
#' @param floating Logical. Floating takes x-axis is taken out of normal flow and places x-axis on svg element directly,
|
|
|
|
#' similar to an absolutely positioned element. Set the offsetX and offsetY then to adjust the position manually
|
|
|
|
#' @param position Setting this option allows you to change the x-axis position. Available options: \code{"top"} and \code{"bottom"}.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param title A list of parameters.
|
|
|
|
#' @param crosshairs A list of parameters.
|
|
|
|
#' @param tooltip A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/xaxis/}
|
2019-06-24 22:07:23 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # X axis title
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_xaxis(title = list(text = "Car's manufacturer"))
|
|
|
|
#'
|
|
|
|
#' # force labels to rotate and increase height
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_xaxis(labels = list(rotateAlways = TRUE, maxHeight = 180))
|
|
|
|
#'
|
|
|
|
#' # force to not rotate
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_xaxis(labels = list(rotate = 0, trim = FALSE))
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' data("economics", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Custom crosshair
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 50),
|
|
|
|
#' mapping = aes(x = date, y = psavert),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_xaxis(
|
|
|
|
#' crosshairs = list(
|
|
|
|
#' opacity = 1,
|
|
|
|
#' width = 2,
|
|
|
|
#' fill = list(color = "red"),
|
|
|
|
#' stroke = list(width = 0)
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#'
|
|
|
|
#'
|
|
|
|
#' # Date format (zoom to see changes)
|
|
|
|
#' apex(
|
|
|
|
#' data = tail(economics, 150),
|
|
|
|
#' mapping = aes(x = date, y = psavert),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_xaxis(
|
|
|
|
#' labels = list(
|
|
|
|
#' datetimeFormatter = list(
|
|
|
|
#' year = "yyyy-MM",
|
|
|
|
#' month = "yyyy-MM-dd",
|
|
|
|
#' day = "yyyy-MM-dd HH:mm"
|
|
|
|
#' )
|
|
|
|
#' )
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_xaxis <- function(ax,
|
|
|
|
type = NULL,
|
|
|
|
categories = NULL,
|
|
|
|
labels = NULL,
|
|
|
|
axisBorder = NULL,
|
|
|
|
axisTicks = NULL,
|
|
|
|
tickAmount = NULL,
|
|
|
|
min = NULL,
|
|
|
|
max = NULL,
|
|
|
|
range = NULL,
|
|
|
|
floating = NULL,
|
|
|
|
position = NULL,
|
|
|
|
title = NULL,
|
|
|
|
crosshairs = NULL,
|
|
|
|
tooltip = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
|
|
|
.ax_opt2(ax, "xaxis", l = dropNulls(params))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Y-axis options
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param opposite Logical. When enabled, will draw the yaxis on the right side of the chart.
|
|
|
|
#' @param tickAmount Number of Tick Intervals to show.
|
|
|
|
#' @param max Lowest number to be set for the y-axis. The graph drawing beyond this number will be clipped off.
|
|
|
|
#' @param min Highest number to be set for the y-axis. The graph drawing beyond this number will be clipped off.
|
|
|
|
#' @param floating Logical. Floating takes y-axis is taken out of normal flow and places y-axis on svg element directly,
|
|
|
|
#' similar to an absolutely positioned element. Set the offsetX and offsetY then to adjust the position manually
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param labels A list of parameters.
|
|
|
|
#' @param axisBorder A list of parameters.
|
|
|
|
#' @param axisTicks A list of parameters.
|
|
|
|
#' @param title A list of parameters.
|
|
|
|
#' @param tooltip A list of parameters.
|
|
|
|
#' @param crosshairs A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/yaxis/}
|
2019-06-24 15:18:38 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' data("economics_long", package = "ggplot2")
|
|
|
|
#' apex(
|
|
|
|
#' data = economics_long,
|
|
|
|
#' mapping = aes(x = date, y = value01, group = variable),
|
|
|
|
#' type = "line"
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_yaxis(
|
|
|
|
#' decimalsInFloat = 2, title = list(text = "Rescaled to [0,1]")
|
|
|
|
#' )
|
2019-06-24 22:07:23 +02:00
|
|
|
#'
|
|
|
|
#' # Format tick labels
|
|
|
|
#' temperature <- data.frame(
|
|
|
|
#' month = head(month.name),
|
|
|
|
#' tp = c(4, -2, 2, 7, 11, 14)
|
|
|
|
#' )
|
|
|
|
#' apex(temperature, aes(month, tp), "line") %>%
|
|
|
|
#' ax_yaxis(
|
|
|
|
#' labels = list(
|
2020-03-03 17:32:30 +01:00
|
|
|
#' formatter = htmlwidgets::JS("function(value) {return value + '\u00b0C';}")
|
2019-06-24 22:07:23 +02:00
|
|
|
#' )
|
|
|
|
#' )
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_yaxis <- function(ax,
|
|
|
|
opposite = NULL,
|
|
|
|
tickAmount = NULL,
|
|
|
|
max = NULL,
|
|
|
|
min = NULL,
|
|
|
|
floating = NULL,
|
|
|
|
labels = NULL,
|
|
|
|
axisBorder = NULL,
|
|
|
|
axisTicks = NULL,
|
|
|
|
title = NULL,
|
|
|
|
tooltip = NULL,
|
|
|
|
crosshairs = NULL,
|
|
|
|
...) {
|
|
|
|
params <- c(as.list(environment()), list(...))[-1]
|
2019-07-15 12:04:45 +02:00
|
|
|
yaxis <- .get_ax_opt(ax, "yaxis")
|
|
|
|
if (inherits(yaxis, "yaxis2")) {
|
|
|
|
yaxis[[1]] <- dropNulls(params)
|
|
|
|
} else {
|
|
|
|
yaxis <- dropNulls(params)
|
|
|
|
class(yaxis) <- c(class(yaxis), "yaxis1")
|
|
|
|
}
|
|
|
|
.ax_opt2(ax, "yaxis", l = yaxis)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Secondary Y-axis options
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @param ... See arguments from \code{\link{ax_yaxis}}.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#'
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("economics_long", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' eco <- economics_long %>%
|
|
|
|
#' filter(variable %in% c("pce", "pop")) %>%
|
|
|
|
#' filter(date >= "2000-01-01")
|
|
|
|
#'
|
|
|
|
#' apex(eco, aes(x = date, y = value, color = variable), type = "line") %>%
|
|
|
|
#' ax_yaxis(title = list(text = "Pce")) %>%
|
|
|
|
#' ax_yaxis2(opposite = TRUE, title = list(text = "Pop"))
|
|
|
|
#'
|
|
|
|
ax_yaxis2 <- function(ax, ...) {
|
|
|
|
params <- dropNulls(list(...))
|
|
|
|
yaxis <- .get_ax_opt(ax, "yaxis")
|
|
|
|
if (inherits(yaxis, "yaxis2")) {
|
|
|
|
yaxis[[2]] <- params
|
|
|
|
} else {
|
|
|
|
yaxis <- list(yaxis, params)
|
|
|
|
class(yaxis) <- c(setdiff(class(yaxis), "yaxis1"), "yaxis2")
|
|
|
|
ax$x$ax_opts$yaxis <- NULL
|
|
|
|
}
|
|
|
|
.ax_opt2(ax, "yaxis", l = yaxis)
|
2018-07-31 22:56:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-15 12:04:45 +02:00
|
|
|
|
|
|
|
|
2018-07-31 22:56:51 +02:00
|
|
|
#' Theme for charts
|
|
|
|
#'
|
|
|
|
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
|
2019-06-24 22:07:23 +02:00
|
|
|
#' @param mode use light or dark theme.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param palette Character. Available palettes: \code{"palette1"} to \code{"palette10"}.
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @param monochrome A list of parameters.
|
2018-07-31 22:56:51 +02:00
|
|
|
#' @param ... Additional parameters.
|
|
|
|
#'
|
|
|
|
#' @return A \code{apexcharts} \code{htmlwidget} object.
|
|
|
|
#' @export
|
|
|
|
#'
|
2018-09-03 23:52:53 +02:00
|
|
|
#' @note See \url{https://apexcharts.com/docs/options/theme/}
|
2019-06-24 22:07:23 +02:00
|
|
|
#'
|
|
|
|
#' @examples
|
|
|
|
#' library(dplyr)
|
|
|
|
#' data("mpg", package = "ggplot2")
|
|
|
|
#' data("diamonds", package = "ggplot2")
|
|
|
|
#'
|
|
|
|
#' # Dark mode
|
|
|
|
#' apex(
|
|
|
|
#' data = count(mpg, manufacturer),
|
|
|
|
#' mapping = aes(x = manufacturer, y = n)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_theme(mode = "dark")
|
|
|
|
#'
|
|
|
|
#' # Use predefined palette (1 to 10)
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut, color),
|
|
|
|
#' mapping = aes(x = color, y = n, fill = cut)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_theme(palette = "palette2")
|
|
|
|
#'
|
|
|
|
#' # monochrome palette
|
|
|
|
#' apex(
|
|
|
|
#' data = count(diamonds, cut, color),
|
|
|
|
#' mapping = aes(x = color, y = n, fill = cut)
|
|
|
|
#' ) %>%
|
|
|
|
#' ax_theme(monochrome = list(enabled = TRUE, color = "#0B6121"))
|
2018-07-31 22:56:51 +02:00
|
|
|
ax_theme <- function(ax,
|
2019-06-24 22:07:23 +02:00
|
|
|
mode = c("light", "dark"),
|
2018-07-31 22:56:51 +02:00
|
|
|
palette = NULL,
|
|
|
|
monochrome = NULL,
|
|
|
|
...) {
|
2019-06-24 22:07:23 +02:00
|
|
|
mode <- match.arg(mode)
|
|
|
|
params <- c(list(
|
|
|
|
mode = mode,
|
|
|
|
palette = palette,
|
|
|
|
monochrome = monochrome
|
|
|
|
), list(...))[-1]
|
2018-07-31 22:56:51 +02:00
|
|
|
.ax_opt2(ax, "theme", l = dropNulls(params))
|
|
|
|
}
|