updated docs
This commit is contained in:
parent
944e63e256
commit
ece66ae816
|
@ -1,5 +1,5 @@
|
||||||
Package: apexcharter
|
Package: apexcharter
|
||||||
Version: 0.0.4.960
|
Version: 0.0.4.970
|
||||||
Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library
|
Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library
|
||||||
Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'.
|
Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'.
|
||||||
Authors@R: c(
|
Authors@R: c(
|
||||||
|
@ -21,7 +21,8 @@ Suggests:
|
||||||
testthat,
|
testthat,
|
||||||
dplyr,
|
dplyr,
|
||||||
knitr,
|
knitr,
|
||||||
rmarkdown
|
rmarkdown,
|
||||||
|
shiny
|
||||||
RoxygenNote: 6.1.1
|
RoxygenNote: 6.1.1
|
||||||
URL: https://github.com/dreamRs/apexcharter
|
URL: https://github.com/dreamRs/apexcharter
|
||||||
BugReports: https://github.com/dreamRs/apexcharter/issues
|
BugReports: https://github.com/dreamRs/apexcharter/issues
|
||||||
|
|
|
@ -79,7 +79,21 @@ events_opts <- function(click = NULL,
|
||||||
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/bar/}.
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/bar/}.
|
||||||
#'
|
#'
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
|
#' @examples
|
||||||
|
#'
|
||||||
|
#' library(dplyr)
|
||||||
|
#' data("mpg", package = "ggplot2")
|
||||||
|
#'
|
||||||
|
#' apex(count(mpg, manufacturer), aes(manufacturer, n)) %>%
|
||||||
|
#' ax_plotOptions(
|
||||||
|
#' bar = bar_opts(
|
||||||
|
#' endingShape = "rounded",
|
||||||
|
#' columnWidth = 100,
|
||||||
|
#' distributed = TRUE
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
|
#'
|
||||||
bar_opts <- function(horizontal = NULL,
|
bar_opts <- function(horizontal = NULL,
|
||||||
endingShape = NULL,
|
endingShape = NULL,
|
||||||
columnWidth = NULL,
|
columnWidth = NULL,
|
||||||
|
@ -116,7 +130,32 @@ bar_opts <- function(horizontal = NULL,
|
||||||
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/heatmap/}.
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/heatmap/}.
|
||||||
#'
|
#'
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
|
#' @examples
|
||||||
|
#'
|
||||||
|
#' df <- expand.grid(
|
||||||
|
#' month = month.name,
|
||||||
|
#' person = c("Obi-Wan", "Luke", "Anakin", "Leia")
|
||||||
|
#' )
|
||||||
|
#' df$value <- sample(0:1, nrow(df), TRUE)
|
||||||
|
#'
|
||||||
|
#' apex(
|
||||||
|
#' data = df,
|
||||||
|
#' mapping = aes(x = month, y = person, fill = value),
|
||||||
|
#' type = "heatmap"
|
||||||
|
#' ) %>%
|
||||||
|
#' ax_plotOptions(
|
||||||
|
#' heatmap = heatmap_opts(
|
||||||
|
#' enableShades = FALSE,
|
||||||
|
#' colorScale = list(
|
||||||
|
#' ranges = list(
|
||||||
|
#' list(from = 0, to = 0.5, color = "#FF0000"),
|
||||||
|
#' list(from = 0.5, to = 1, color = "#088A08")
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
|
#'
|
||||||
heatmap_opts <- function(radius = NULL,
|
heatmap_opts <- function(radius = NULL,
|
||||||
enableShades = NULL,
|
enableShades = NULL,
|
||||||
shadeIntensity = NULL,
|
shadeIntensity = NULL,
|
||||||
|
@ -210,7 +249,7 @@ radialBar_opts <- function(size = NULL,
|
||||||
#' Use these options in \code{\link{ax_plotOptions}}.
|
#' Use these options in \code{\link{ax_plotOptions}}.
|
||||||
#'
|
#'
|
||||||
#' @param size Numeric. Custom size of the pie which will override the default size calculations.
|
#' @param size Numeric. Custom size of the pie which will override the default size calculations.
|
||||||
#' @param donut List with two fields \code{donutSize} (Donut / ring size in percentage relative to the total pie area.)
|
#' @param donut List with two fields \code{size} (Donut / ring size in percentage relative to the total pie area.)
|
||||||
#' and \code{background} (The background color of the pie).
|
#' and \code{background} (The background color of the pie).
|
||||||
#' @param customScale Numeric. Transform the scale of whole pie/donut overriding the default calculations.
|
#' @param customScale Numeric. Transform the scale of whole pie/donut overriding the default calculations.
|
||||||
#' @param offsetX Numeric. Sets the left offset of the whole pie area.
|
#' @param offsetX Numeric. Sets the left offset of the whole pie area.
|
||||||
|
@ -221,7 +260,18 @@ radialBar_opts <- function(size = NULL,
|
||||||
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/pie/}.
|
#' @note See \url{https://apexcharts.com/docs/options/plotoptions/pie/}.
|
||||||
#'
|
#'
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
|
#' @examples
|
||||||
|
#'
|
||||||
|
#' library(dplyr)
|
||||||
|
#' data("mpg", package = "ggplot2")
|
||||||
|
#'
|
||||||
|
#' apex(count(mpg, cyl), aes(cyl, n), type = "donut") %>%
|
||||||
|
#' ax_plotOptions(
|
||||||
|
#' pie = pie_opts(
|
||||||
|
#' donut = list(size = "90%", background = "#BABABA")
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
pie_opts <- function(size = NULL,
|
pie_opts <- function(size = NULL,
|
||||||
donut = NULL,
|
donut = NULL,
|
||||||
customScale = NULL,
|
customScale = NULL,
|
||||||
|
|
16
R/apex.R
16
R/apex.R
|
@ -57,6 +57,9 @@ apex <- function(data, mapping, type = "column", ..., auto_update = TRUE, width
|
||||||
type <- match.arg(type, c("column", "bar", "line", "area", "spline", "area-spline",
|
type <- match.arg(type, c("column", "bar", "line", "area", "spline", "area-spline",
|
||||||
"pie", "donut", "radialBar", "radar", "scatter", "heatmap"))
|
"pie", "donut", "radialBar", "radar", "scatter", "heatmap"))
|
||||||
data <- as.data.frame(data)
|
data <- as.data.frame(data)
|
||||||
|
if (identical(type, "heatmap")) {
|
||||||
|
mapping <- rename_aes_heatmap(mapping)
|
||||||
|
}
|
||||||
mapdata <- lapply(mapping, rlang::eval_tidy, data = data)
|
mapdata <- lapply(mapping, rlang::eval_tidy, data = data)
|
||||||
if (type %in% c("pie", "donut", "radialBar")) {
|
if (type %in% c("pie", "donut", "radialBar")) {
|
||||||
opts <- list(
|
opts <- list(
|
||||||
|
@ -117,6 +120,19 @@ is_grouped <- function(x) {
|
||||||
any(c("colour", "fill", "group") %in% x)
|
any(c("colour", "fill", "group") %in% x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rename_aes_heatmap <- function(mapping) {
|
||||||
|
n_mapping <- names(mapping)
|
||||||
|
n_mapping[n_mapping == "y"] <- "group"
|
||||||
|
if ("fill" %in% n_mapping) {
|
||||||
|
n_mapping[n_mapping == "fill"] <- "y"
|
||||||
|
}
|
||||||
|
if ("colour" %in% n_mapping) {
|
||||||
|
n_mapping[n_mapping == "colour"] <- "y"
|
||||||
|
}
|
||||||
|
names(mapping) <- n_mapping
|
||||||
|
return(mapping)
|
||||||
|
}
|
||||||
|
|
||||||
rename_aes <- function(mapping) {
|
rename_aes <- function(mapping) {
|
||||||
if ("colour" %in% names(mapping)) {
|
if ("colour" %in% names(mapping)) {
|
||||||
names(mapping)[names(mapping) == "colour"] <- "group"
|
names(mapping)[names(mapping) == "colour"] <- "group"
|
||||||
|
|
|
@ -15,15 +15,39 @@
|
||||||
#' @examples
|
#' @examples
|
||||||
#'
|
#'
|
||||||
#' library(apexcharter)
|
#' library(apexcharter)
|
||||||
#'
|
#'
|
||||||
|
#' # Use raw API by passing a list of
|
||||||
|
#' # parameters to the function
|
||||||
|
#'
|
||||||
#' apexchart(ax_opts = list(
|
#' apexchart(ax_opts = list(
|
||||||
#' chart = list(type = "bar"),
|
#' chart = list(
|
||||||
|
#' type = "bar"
|
||||||
|
#' ),
|
||||||
#' series = list(list(
|
#' series = list(list(
|
||||||
#' name = "Example",
|
#' name = "Example",
|
||||||
#' data = sample(1:100, 5)
|
#' data = sample(1:100, 5)
|
||||||
#' )),
|
#' )),
|
||||||
#' xaxis = list(categories = LETTERS[1:5])
|
#' xaxis = list(
|
||||||
|
#' categories = LETTERS[1:5]
|
||||||
|
#' )
|
||||||
#' ))
|
#' ))
|
||||||
|
#'
|
||||||
|
#'
|
||||||
|
#' # Or use apexchart() to initialize the chart
|
||||||
|
#' # before passing parameters
|
||||||
|
#'
|
||||||
|
#' apexchart() %>%
|
||||||
|
#' ax_chart(type = "bar") %>%
|
||||||
|
#' ax_series(
|
||||||
|
#' list(
|
||||||
|
#' name = "Example",
|
||||||
|
#' data = sample(1:100, 5)
|
||||||
|
#' )
|
||||||
|
#' ) %>%
|
||||||
|
#' ax_xaxis(
|
||||||
|
#' categories = LETTERS[1:5]
|
||||||
|
#' )
|
||||||
|
#'
|
||||||
apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
|
||||||
|
|
||||||
# forward options using x
|
# forward options using x
|
||||||
|
@ -75,6 +99,44 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
|
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#'
|
||||||
|
#' if (interactive()) {
|
||||||
|
#' library(shiny)
|
||||||
|
#'
|
||||||
|
#' ui <- fluidPage(
|
||||||
|
#' fluidRow(
|
||||||
|
#' column(
|
||||||
|
#' width = 8, offset = 2,
|
||||||
|
#' tags$h2("Apexchart in Shiny"),
|
||||||
|
#' actionButton("redraw", "Redraw chart"),
|
||||||
|
#' apexchartOutput("chart")
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
|
#' )
|
||||||
|
#'
|
||||||
|
#' server <- function(input, output, session) {
|
||||||
|
#'
|
||||||
|
#' output$chart <- renderApexchart({
|
||||||
|
#' input$redraw
|
||||||
|
#' apexchart() %>%
|
||||||
|
#' ax_chart(type = "bar") %>%
|
||||||
|
#' ax_series(
|
||||||
|
#' list(
|
||||||
|
#' name = "Example",
|
||||||
|
#' data = sample(1:100, 5)
|
||||||
|
#' )
|
||||||
|
#' ) %>%
|
||||||
|
#' ax_xaxis(
|
||||||
|
#' categories = LETTERS[1:5]
|
||||||
|
#' )
|
||||||
|
#' })
|
||||||
|
#'
|
||||||
|
#' }
|
||||||
|
#'
|
||||||
|
#' shinyApp(ui, server)
|
||||||
|
#' }
|
||||||
apexchartOutput <- function(outputId, width = '100%', height = '400px'){
|
apexchartOutput <- function(outputId, width = '100%', height = '400px'){
|
||||||
htmlwidgets::shinyWidgetOutput(outputId, 'apexcharter', width, height, package = 'apexcharter')
|
htmlwidgets::shinyWidgetOutput(outputId, 'apexcharter', width, height, package = 'apexcharter')
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,36 @@ Create a apexcharts.js widget
|
||||||
|
|
||||||
library(apexcharter)
|
library(apexcharter)
|
||||||
|
|
||||||
|
# Use raw API by passing a list of
|
||||||
|
# parameters to the function
|
||||||
|
|
||||||
apexchart(ax_opts = list(
|
apexchart(ax_opts = list(
|
||||||
chart = list(type = "bar"),
|
chart = list(
|
||||||
|
type = "bar"
|
||||||
|
),
|
||||||
series = list(list(
|
series = list(list(
|
||||||
name = "Example",
|
name = "Example",
|
||||||
data = sample(1:100, 5)
|
data = sample(1:100, 5)
|
||||||
)),
|
)),
|
||||||
xaxis = list(categories = LETTERS[1:5])
|
xaxis = list(
|
||||||
|
categories = LETTERS[1:5]
|
||||||
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
# Or use apexchart() to initialize the chart
|
||||||
|
# before passing parameters
|
||||||
|
|
||||||
|
apexchart() \%>\%
|
||||||
|
ax_chart(type = "bar") \%>\%
|
||||||
|
ax_series(
|
||||||
|
list(
|
||||||
|
name = "Example",
|
||||||
|
data = sample(1:100, 5)
|
||||||
|
)
|
||||||
|
) \%>\%
|
||||||
|
ax_xaxis(
|
||||||
|
categories = LETTERS[1:5]
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,3 +28,41 @@ is useful if you want to save an expression in a variable.}
|
||||||
Output and render functions for using apexcharter within Shiny
|
Output and render functions for using apexcharter within Shiny
|
||||||
applications and interactive Rmd documents.
|
applications and interactive Rmd documents.
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
|
||||||
|
if (interactive()) {
|
||||||
|
library(shiny)
|
||||||
|
|
||||||
|
ui <- fluidPage(
|
||||||
|
fluidRow(
|
||||||
|
column(
|
||||||
|
width = 8, offset = 2,
|
||||||
|
tags$h2("Apexchart in Shiny"),
|
||||||
|
actionButton("redraw", "Redraw chart"),
|
||||||
|
apexchartOutput("chart")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
server <- function(input, output, session) {
|
||||||
|
|
||||||
|
output$chart <- renderApexchart({
|
||||||
|
input$redraw
|
||||||
|
apexchart() \%>\%
|
||||||
|
ax_chart(type = "bar") \%>\%
|
||||||
|
ax_series(
|
||||||
|
list(
|
||||||
|
name = "Example",
|
||||||
|
data = sample(1:100, 5)
|
||||||
|
)
|
||||||
|
) \%>\%
|
||||||
|
ax_xaxis(
|
||||||
|
categories = LETTERS[1:5]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
shinyApp(ui, server)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ ax_yaxis2(ax, ...)
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{ax}{A \code{apexcharts} \code{htmlwidget} object.}
|
\item{ax}{A \code{apexcharts} \code{htmlwidget} object.}
|
||||||
|
|
||||||
\item{...}{See arguments from \code{\link{ax_yaxis}}}
|
\item{...}{See arguments from \code{\link{ax_yaxis}}.}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
A \code{apexcharts} \code{htmlwidget} object.
|
A \code{apexcharts} \code{htmlwidget} object.
|
||||||
|
|
|
@ -31,3 +31,18 @@ Use these options in \code{\link{ax_plotOptions}}.
|
||||||
\note{
|
\note{
|
||||||
See \url{https://apexcharts.com/docs/options/plotoptions/bar/}.
|
See \url{https://apexcharts.com/docs/options/plotoptions/bar/}.
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
|
||||||
|
library(dplyr)
|
||||||
|
data("mpg", package = "ggplot2")
|
||||||
|
|
||||||
|
apex(count(mpg, manufacturer), aes(manufacturer, n)) \%>\%
|
||||||
|
ax_plotOptions(
|
||||||
|
bar = bar_opts(
|
||||||
|
endingShape = "rounded",
|
||||||
|
columnWidth = 100,
|
||||||
|
distributed = TRUE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -24,3 +24,29 @@ Use these options in \code{\link{ax_plotOptions}}.
|
||||||
\note{
|
\note{
|
||||||
See \url{https://apexcharts.com/docs/options/plotoptions/heatmap/}.
|
See \url{https://apexcharts.com/docs/options/plotoptions/heatmap/}.
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
|
||||||
|
df <- expand.grid(
|
||||||
|
month = month.name,
|
||||||
|
person = c("Obi-Wan", "Luke", "Anakin", "Leia")
|
||||||
|
)
|
||||||
|
df$value <- sample(0:1, nrow(df), TRUE)
|
||||||
|
|
||||||
|
apex(
|
||||||
|
data = df,
|
||||||
|
mapping = aes(x = month, y = person, fill = value),
|
||||||
|
type = "heatmap"
|
||||||
|
) \%>\%
|
||||||
|
ax_plotOptions(
|
||||||
|
heatmap = heatmap_opts(
|
||||||
|
enableShades = FALSE,
|
||||||
|
colorScale = list(
|
||||||
|
ranges = list(
|
||||||
|
list(from = 0, to = 0.5, color = "#FF0000"),
|
||||||
|
list(from = 0.5, to = 1, color = "#088A08")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ pie_opts(size = NULL, donut = NULL, customScale = NULL,
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{size}{Numeric. Custom size of the pie which will override the default size calculations.}
|
\item{size}{Numeric. Custom size of the pie which will override the default size calculations.}
|
||||||
|
|
||||||
\item{donut}{List with two fields \code{donutSize} (Donut / ring size in percentage relative to the total pie area.)
|
\item{donut}{List with two fields \code{size} (Donut / ring size in percentage relative to the total pie area.)
|
||||||
and \code{background} (The background color of the pie).}
|
and \code{background} (The background color of the pie).}
|
||||||
|
|
||||||
\item{customScale}{Numeric. Transform the scale of whole pie/donut overriding the default calculations.}
|
\item{customScale}{Numeric. Transform the scale of whole pie/donut overriding the default calculations.}
|
||||||
|
@ -29,3 +29,15 @@ Use these options in \code{\link{ax_plotOptions}}.
|
||||||
\note{
|
\note{
|
||||||
See \url{https://apexcharts.com/docs/options/plotoptions/pie/}.
|
See \url{https://apexcharts.com/docs/options/plotoptions/pie/}.
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
|
||||||
|
library(dplyr)
|
||||||
|
data("mpg", package = "ggplot2")
|
||||||
|
|
||||||
|
apex(count(mpg, cyl), aes(cyl, n), type = "donut") \%>\%
|
||||||
|
ax_plotOptions(
|
||||||
|
pie = pie_opts(
|
||||||
|
donut = list(size = "90\%", background = "#BABABA")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -200,9 +200,11 @@ txhousing2 <- txhousing %>%
|
||||||
filter(city %in% head(unique(city)), year %in% c(2000, 2001)) %>%
|
filter(city %in% head(unique(city)), year %in% c(2000, 2001)) %>%
|
||||||
rename(val_med = median)
|
rename(val_med = median)
|
||||||
|
|
||||||
apex(data = txhousing2,
|
apex(
|
||||||
type = "heatmap",
|
data = txhousing2,
|
||||||
mapping = aes(x = date, y = scales::rescale(val_med), group = city)) %>%
|
type = "heatmap",
|
||||||
|
mapping = aes(x = date, y = city, fill = scales::rescale(val_med))
|
||||||
|
) %>%
|
||||||
ax_dataLabels(enabled = FALSE) %>%
|
ax_dataLabels(enabled = FALSE) %>%
|
||||||
ax_colors("#008FFB")
|
ax_colors("#008FFB")
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue