added examples

This commit is contained in:
pvictor 2019-06-24 15:18:38 +02:00
parent 263222aeb8
commit 2cf9929612
24 changed files with 1007 additions and 23 deletions

View File

@ -68,7 +68,7 @@ events_opts <- function(click = NULL,
#' Use these options in \code{\link{ax_plotOptions}}.
#'
#' @param horizontal Logical. This option will turn a column chart into a horiontal bar chart.
#' @param endingShape Available Options: \code{"flat"}, \code{"rounded"} or \code{"arrow"}.
#' @param endingShape Available Options: \code{"flat"} or \code{"rounded"}.
#' @param columnWidth In column charts, columnWidth is the percentage of the available width in the grid-rect.
#' @param barHeight In horizontal bar charts, barHeight is the percentage of the available height in the grid-rect.
#' @param distributed Logical. Turn this option to make the bars discrete. Each value indicates one bar per series.
@ -152,7 +152,32 @@ heatmap_opts <- function(radius = NULL,
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/radialbar/}.
#'
#' @export
#'
#'
#' @examples
#' apexchart() %>%
#' ax_chart(type = "radialBar") %>%
#' ax_plotOptions(
#' radialBar = radialBar_opts(
#' startAngle = -135,
#' endAngle = 135,
#' dataLabels = list(
#' name = list(
#' fontSize = "16px",
#' # color = undefined,
#' offsetY = 120
#' ),
#' value = list(
#' offsetY = 76,
#' fontSize = "22px",
#' # color = undefined,
#' formatter = htmlwidgets::JS("function (val) {return val + '%';}")
#' )
#' )
#' )
#' ) %>%
#' ax_stroke(dashArray = 4) %>%
#' ax_series(70) %>%
#' ax_labels("Indicator")
radialBar_opts <- function(size = NULL,
inverseOrder = NULL,
startAngle = NULL,

View File

@ -19,7 +19,104 @@
#'
#' @return A \code{apexcharts} \code{htmlwidget} object.
#' @export
#'
#'
#' @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"
#' )
#' )
#' ))
#' )
ax_annotations <- function(ax,
position = NULL,
yaxis = NULL,
@ -55,7 +152,31 @@ ax_annotations <- function(ax,
#'
#' @return A \code{apexcharts} \code{htmlwidget} object.
#' @export
#'
#'
#' @examples
#' library(dplyr)
#' data("diamonds", package = "ggplot2")
#'
#' # Stack bar type
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_chart(stacked = TRUE)
#'
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_chart(stacked = TRUE, stackType = "100%")
#'
#'
#' # Toolbar
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_chart(toolbar = list(show = FALSE))
ax_chart <- function(ax,
type = NULL,
stacked = NULL,
@ -90,7 +211,41 @@ ax_chart <- function(ax,
#'
#' @return A \code{apexcharts} \code{htmlwidget} object.
#' @export
#'
#'
#' @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")
ax_plotOptions <- function(ax,
bar = NULL,
heatmap = NULL,
@ -111,7 +266,25 @@ ax_plotOptions <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/colors/}
#'
#'
#' @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")
#'
#'
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_colors(scales::brewer_pal(palette = "Set2")(7))
ax_colors <- function(ax, ...) {
args <- list(...)
if (length(args) == 1) {
@ -138,7 +311,17 @@ ax_colors <- function(ax, ...) {
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/datalabels/}
#'
#'
#' @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)
ax_dataLabels <- function(ax,
enabled = NULL,
textAnchor = NULL,
@ -169,7 +352,41 @@ ax_dataLabels <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/fill/}
#'
#'
#' @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)
#' ))
ax_fill <- function(ax,
type = NULL,
colors = NULL,
@ -202,6 +419,36 @@ ax_fill <- function(ax,
#'
#' @note See \url{https://apexcharts.com/docs/options/grid/}
#'
#' @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))
#' )
ax_grid <- function(ax,
show = NULL,
borderColor = NULL,
@ -231,6 +478,18 @@ ax_grid <- function(ax,
#' @name ax_labels
#'
#' @note See \url{https://apexcharts.com/docs/options/labels/}
#'
#' @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"))
ax_labels <- function(ax, ...) {
.ax_opt(ax, "labels", ...)
}
@ -247,8 +506,10 @@ ax_labels2 <- function(ax, labels) {
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
#' @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"}.
#' @param showForSingleSeries Show legend even if there is just 1 series.
#' @param showForNullSeries Allows you to hide a particular legend if its series contains all null values.
#' @param showForZeroSeries Allows you to hide a particular legend if its series contains all 0 values.
#' @param horizontalAlign Available options for horizontal alignment: \code{"right"}, \code{"center"}, \code{"left"}.
#' @param verticalAlign Available options for vertical alignment: \code{"top"}, \code{"middle"}, \code{"bottom"}
#' @param fontSize Sets the fontSize of legend text elements
#' @param textAnchor The alignment of text relative to legends drawing position
#' @param offsetY Sets the top offset for legend container.
@ -272,11 +533,31 @@ ax_labels2 <- function(ax, labels) {
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/legend/}
#'
#' @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)
ax_legend <- function(ax,
show = NULL,
position = NULL,
showForSingleSeries = NULL,
showForNullSeries= NULL,
showForZeroSeries = NULL,
horizontalAlign = NULL,
verticalAlign = NULL,
fontSize = NULL,
textAnchor = NULL,
offsetY = NULL,
@ -316,6 +597,16 @@ ax_legend <- function(ax,
#'
#' @note See \url{https://apexcharts.com/docs/options/markers/}
#'
#' @examples
#' data("economics", package = "ggplot2")
#'
#' # show points
#' apex(
#' data = tail(economics, 20),
#' type = "line",
#' mapping = aes(x = date, y = uempmed)
#' ) %>%
#' ax_markers(size = 6)
ax_markers <- function(ax,
size = NULL,
colors = NULL,
@ -333,7 +624,7 @@ ax_markers <- function(ax,
.ax_opt2(ax, "markers", l = dropNulls(params))
}
#
#' No data specification
#'
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
@ -370,6 +661,33 @@ ax_noData <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/responsive/}
#'
#' @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"
#' )
#' )
#' )
#' )
ax_responsive <- function(ax, ...) {
.ax_opt(ax, "responsive", ...)
}
@ -430,6 +748,24 @@ ax_series2 <- function(ax, l) {
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/states/}
#'
#' @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"
#' )
#' )
#' )
ax_states <- function(ax,
normal = NULL,
hover = NULL,
@ -456,6 +792,17 @@ ax_states <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/title/}
#'
#' @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"
#' )
ax_title <- function(ax,
text = NULL,
align = NULL,
@ -486,6 +833,20 @@ ax_title <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/subtitle/}
#'
#' @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"
#' )
ax_subtitle <- function(ax,
text = NULL,
align = NULL,
@ -520,6 +881,29 @@ ax_subtitle <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/stroke/}
#'
#' @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)
#' )
ax_stroke <- function(ax,
show = NULL,
curve = NULL,
@ -557,6 +941,35 @@ ax_stroke <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/tooltip/}
#'
#' @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")
#' )
ax_tooltip <- function(ax,
enabled = NULL,
shared = NULL,
@ -646,6 +1059,17 @@ ax_xaxis <- function(ax,
#' @export
#'
#' @note See \url{https://apexcharts.com/docs/options/yaxis/}
#'
#' @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]")
#' )
ax_yaxis <- function(ax,
opposite = NULL,
tickAmount = NULL,

View File

@ -16,6 +16,43 @@
#' @importFrom rlang eval_tidy as_label
#' @importFrom utils modifyList
#'
#' @examples
#' library(dplyr)
#'
#'
#' # make a barchart with a frequency table
#' data("mpg", package = "ggplot2")
#' apex(
#' data = count(mpg, manufacturer),
#' mapping = aes(x = manufacturer, y = n),
#' type = "bar"
#' )
#'
#' # timeseries
#' data("economics", package = "ggplot2")
#' apex(
#' data = economics,
#' mapping = aes(x = date, y = uempmed),
#' type = "line"
#' )
#'
#' # you can add option to apex result :
#' apex(
#' data = economics,
#' mapping = aes(x = date, y = uempmed),
#' type = "line"
#' ) %>%
#' ax_stroke(width = 1)
#'
#'
#'
#' # with group variable
#' data("economics_long", package = "ggplot2")
#' apex(
#' data = economics_long,
#' mapping = aes(x = date, y = value01, group = variable),
#' type = "line"
#' )
apex <- function(data, mapping, type = "column", ..., auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
type <- match.arg(type, c("column", "bar", "line", "area", "spline", "area-spline",
"pie", "donut", "radialBar", "radar", "scatter", "heatmap"))

View File

@ -30,9 +30,9 @@ head(unhcr_popstats_2017)
categories_unhcr <- count(unhcr_popstats_2017, population_type, sort = TRUE)
apexcharter() %>%
apexchart() %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = barOpts(
ax_plotOptions(bar = bar_opts(
horizontal = TRUE,
dataLabels = list(
position = "center"
@ -67,7 +67,7 @@ refugees <- unhcr_popstats_2017 %>%
)
apexcharter() %>%
apexchart() %>%
ax_chart(type = "bar", stacked = FALSE) %>%
ax_dataLabels(enabled = FALSE) %>%
ax_series(
@ -115,7 +115,7 @@ apexcharter() %>%
count(unhcr_popstats_2017, continent = continent_residence, population_type, wt = value)
apexcharter() %>%
apexchart() %>%
ax_chart(type = "bar", stacked = TRUE, stackType = "100%") %>%
ax_plotOptions(bar = barOpts(horizontal = TRUE)) %>%
ax_series(

View File

@ -28,3 +28,41 @@ apex(data, mapping, type = "column", ..., auto_update = TRUE,
\description{
Quick Apex Chart
}
\examples{
library(dplyr)
# make a barchart with a frequency table
data("mpg", package = "ggplot2")
apex(
data = count(mpg, manufacturer),
mapping = aes(x = manufacturer, y = n),
type = "bar"
)
# timeseries
data("economics", package = "ggplot2")
apex(
data = economics,
mapping = aes(x = date, y = uempmed),
type = "line"
)
# you can add option to apex result :
apex(
data = economics,
mapping = aes(x = date, y = uempmed),
type = "line"
) \%>\%
ax_stroke(width = 1)
# with group variable
data("economics_long", package = "ggplot2")
apex(
data = economics_long,
mapping = aes(x = date, y = value01, group = variable),
type = "line"
)
}

View File

@ -29,3 +29,101 @@ Annotations properties
\note{
See \url{https://apexcharts.com/docs/options/annotations/}.
}
\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"
)
)
))
)
}

View File

@ -54,3 +54,28 @@ A \code{apexcharts} \code{htmlwidget} object.
\description{
Chart parameters
}
\examples{
library(dplyr)
data("diamonds", package = "ggplot2")
# Stack bar type
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
ax_chart(stacked = TRUE)
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
ax_chart(stacked = TRUE, stackType = "100\%")
# Toolbar
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
ax_chart(toolbar = list(show = FALSE))
}

View File

@ -20,3 +20,22 @@ Colors
\note{
See \url{https://apexcharts.com/docs/options/colors/}
}
\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")
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
ax_colors(scales::brewer_pal(palette = "Set2")(7))
}

View File

@ -37,3 +37,14 @@ Labels on data
\note{
See \url{https://apexcharts.com/docs/options/datalabels/}
}
\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)
}

View File

@ -34,3 +34,38 @@ Fill property
\note{
See \url{https://apexcharts.com/docs/options/fill/}
}
\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)
))
}

View File

@ -40,3 +40,34 @@ Add grids on chart
\note{
See \url{https://apexcharts.com/docs/options/grid/}
}
\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))
)
}

View File

@ -26,3 +26,15 @@ Alternative axis labels
\note{
See \url{https://apexcharts.com/docs/options/labels/}
}
\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"))
}

View File

@ -4,11 +4,13 @@
\alias{ax_legend}
\title{Legend properties}
\usage{
ax_legend(ax, show = NULL, position = NULL, horizontalAlign = NULL,
verticalAlign = NULL, fontSize = NULL, textAnchor = NULL,
offsetY = NULL, offsetX = NULL, formatter = NULL, labels = NULL,
markers = NULL, itemMargin = NULL, containerMargin = NULL,
onItemClick = NULL, onItemHover = NULL, floating = NULL, ...)
ax_legend(ax, show = NULL, position = NULL,
showForSingleSeries = NULL, showForNullSeries = NULL,
showForZeroSeries = NULL, horizontalAlign = NULL, fontSize = NULL,
textAnchor = NULL, offsetY = NULL, offsetX = NULL,
formatter = NULL, labels = NULL, markers = NULL,
itemMargin = NULL, containerMargin = NULL, onItemClick = NULL,
onItemHover = NULL, floating = NULL, ...)
}
\arguments{
\item{ax}{A \code{apexcharts} \code{htmlwidget} object.}
@ -17,9 +19,13 @@ ax_legend(ax, show = NULL, position = NULL, horizontalAlign = NULL,
\item{position}{Available position options for legend: \code{"top"}, \code{"right"}, \code{"bottom"}, \code{"left"}.}
\item{horizontalAlign}{Available options for horizontal alignment: \code{"right"}, \code{"center"}, \code{"left"}.}
\item{showForSingleSeries}{Show legend even if there is just 1 series.}
\item{verticalAlign}{Available options for vertical alignment: \code{"top"}, \code{"middle"}, \code{"bottom"}}
\item{showForNullSeries}{Allows you to hide a particular legend if its series contains all null values.}
\item{showForZeroSeries}{Allows you to hide a particular legend if its series contains all 0 values.}
\item{horizontalAlign}{Available options for horizontal alignment: \code{"right"}, \code{"center"}, \code{"left"}.}
\item{fontSize}{Sets the fontSize of legend text elements}
@ -61,3 +67,21 @@ Legend properties
\note{
See \url{https://apexcharts.com/docs/options/legend/}
}
\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)
}

View File

@ -45,3 +45,14 @@ Markers properties
\note{
See \url{https://apexcharts.com/docs/options/markers/}
}
\examples{
data("economics", package = "ggplot2")
# show points
apex(
data = tail(economics, 20),
type = "line",
mapping = aes(x = date, y = uempmed)
) \%>\%
ax_markers(size = 6)
}

View File

@ -26,3 +26,38 @@ A \code{apexcharts} \code{htmlwidget} object.
\description{
Specific options for chart
}
\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")
}

View File

@ -20,3 +20,30 @@ Responsive options
\note{
See \url{https://apexcharts.com/docs/options/responsive/}
}
\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"
)
)
)
)
}

View File

@ -26,3 +26,21 @@ Charts' states
\note{
See \url{https://apexcharts.com/docs/options/states/}
}
\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"
)
)
)
}

View File

@ -38,3 +38,26 @@ Stroke properties
\note{
See \url{https://apexcharts.com/docs/options/stroke/}
}
\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)
)
}

View File

@ -36,3 +36,17 @@ Chart's subtitle
\note{
See \url{https://apexcharts.com/docs/options/subtitle/}
}
\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"
)
}

View File

@ -36,3 +36,14 @@ Chart's title
\note{
See \url{https://apexcharts.com/docs/options/title/}
}
\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"
)
}

View File

@ -54,3 +54,32 @@ Tooltip options
\note{
See \url{https://apexcharts.com/docs/options/tooltip/}
}
\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")
)
}

View File

@ -46,3 +46,14 @@ Y-axis options
\note{
See \url{https://apexcharts.com/docs/options/yaxis/}
}
\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]")
)
}

View File

@ -11,7 +11,7 @@ bar_opts(horizontal = NULL, endingShape = NULL, columnWidth = NULL,
\arguments{
\item{horizontal}{Logical. This option will turn a column chart into a horiontal bar chart.}
\item{endingShape}{Available Options: \code{"flat"}, \code{"rounded"} or \code{"arrow"}.}
\item{endingShape}{Available Options: \code{"flat"} or \code{"rounded"}.}
\item{columnWidth}{In column charts, columnWidth is the percentage of the available width in the grid-rect.}

View File

@ -35,3 +35,29 @@ Use these options in \code{\link{ax_plotOptions}}.
\note{
See \url{https://apexcharts.com/docs/options/plotoptions/radialbar/}.
}
\examples{
apexchart() \%>\%
ax_chart(type = "radialBar") \%>\%
ax_plotOptions(
radialBar = radialBar_opts(
startAngle = -135,
endAngle = 135,
dataLabels = list(
name = list(
fontSize = "16px",
# color = undefined,
offsetY = 120
),
value = list(
offsetY = 76,
fontSize = "22px",
# color = undefined,
formatter = htmlwidgets::JS("function (val) {return val + '\%';}")
)
)
)
) \%>\%
ax_stroke(dashArray = 4) \%>\%
ax_series(70) \%>\%
ax_labels("Indicator")
}