apexcharter/README.md

164 lines
3.7 KiB
Markdown
Raw Permalink Normal View History

2018-07-30 23:04:08 +02:00
# apexcharter
2022-12-09 09:48:13 +01:00
> Htmlwidget for [apexcharts.js](https://github.com/apexcharts/apexcharts.js) : A modern JavaScript charting library to build interactive charts and visualizations with simple API. See the [online documentation](https://dreamrs.github.io/apexcharter/) for examples.
2018-07-30 23:04:08 +02:00
2019-11-26 10:11:57 +01:00
<!-- badges: start -->
2022-12-09 09:50:30 +01:00
[![CRAN status](https://www.r-pkg.org/badges/version/apexcharter)](https://CRAN.R-project.org/package=apexcharter)
2023-01-08 19:23:11 +01:00
[![cran checks](https://badges.cranchecks.info/worst/apexcharter.svg)](https://cran.r-project.org/web/checks/check_results_apexcharter.html)
2021-10-21 14:36:25 +02:00
[![Codecov test coverage](https://codecov.io/gh/dreamRs/apexcharter/branch/master/graph/badge.svg)](https://app.codecov.io/gh/dreamRs/apexcharter?branch=master)
2023-01-08 18:45:39 +01:00
[![R-CMD-check](https://github.com/dreamRs/apexcharter/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dreamRs/apexcharter/actions/workflows/R-CMD-check.yaml)
2019-11-26 10:11:57 +01:00
<!-- badges: end -->
2018-09-09 21:21:42 +02:00
2019-02-14 09:59:08 +01:00
2018-07-30 23:04:08 +02:00
## Installation
2021-10-21 14:36:25 +02:00
Install from [CRAN](https://CRAN.R-project.org/package=apexcharter) with:
2019-07-29 09:32:57 +02:00
```r
install.packages("apexcharter")
```
2021-09-17 11:24:35 +02:00
Or install the development version from [GitHub](https://github.com/dreamRs/apexcharter) with:
2018-07-30 23:04:08 +02:00
2021-09-17 11:24:35 +02:00
```r
# install.packages("remotes")
remotes::install_github("dreamRs/apexcharter")
2018-07-30 23:04:08 +02:00
```
2019-02-14 09:59:08 +01:00
2019-02-14 18:33:35 +01:00
## Quick Charts
Use `apex` function to quickly create visualizations :
```r
library(apexcharter)
data("mpg", package = "ggplot2")
2021-01-15 10:53:51 +01:00
apex(data = mpg, type = "bar", mapping = aes(manufacturer))
2019-02-14 18:33:35 +01:00
```
![](man/figures/apex-bar.png)
With datetime:
```r
data("economics", package = "ggplot2")
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed)) %>%
ax_stroke(width = 1)
```
![](man/figures/apex-line.png)
## Full API
2018-07-31 23:24:35 +02:00
2019-02-14 18:40:32 +01:00
All methods from ApexCharts are available with function like `ax_*` compatible with pipe from `magrittr` :
2018-07-31 23:24:35 +02:00
```r
library(apexcharter)
2019-02-14 18:40:32 +01:00
data(mpg, package = "ggplot2")
2018-07-31 23:24:35 +02:00
2019-02-15 22:33:14 +01:00
apexchart() %>%
2018-07-31 23:24:35 +02:00
ax_chart(type = "bar") %>%
2019-02-17 22:07:04 +01:00
ax_plotOptions(bar = bar_opts(
2018-07-31 23:24:35 +02:00
horizontal = FALSE,
endingShape = "flat",
columnWidth = "70%",
dataLabels = list(
position = "top"
))
) %>%
ax_grid(
show = TRUE,
2019-02-14 18:40:32 +01:00
position = "front",
borderColor = "#FFF"
2018-07-31 23:24:35 +02:00
) %>%
ax_series(list(
name = "Count",
2021-01-15 10:53:51 +01:00
data = tapply(mpg$manufacturer, mpg$manufacturer, length)
2018-07-31 23:24:35 +02:00
)) %>%
ax_colors("#112446") %>%
2021-01-15 10:53:51 +01:00
ax_xaxis(categories = unique(mpg$manufacturer)) %>%
2018-07-31 23:24:35 +02:00
ax_title(text = "Number of models") %>%
ax_subtitle(text = "Data from ggplot2")
```
2019-02-14 18:40:32 +01:00
![](man/figures/apexcharter-full-bar.png)
2018-07-31 23:24:35 +02:00
2018-07-30 23:04:08 +02:00
## Raw API
2018-07-31 23:24:35 +02:00
Pass a list of parameters to the function:
2018-07-30 23:04:08 +02:00
2020-02-14 18:13:24 +01:00
```r
2019-02-15 22:33:14 +01:00
apexchart(ax_opts = list(
2018-07-30 23:04:08 +02:00
chart = list(
type = "line"
),
stroke = list(
curve = "smooth"
),
grid = list(
borderColor = "#e7e7e7",
row = list(
colors = c("#f3f3f3", "transparent"),
opacity = 0.5
)
),
dataLabels = list(
enabled = TRUE
),
markers = list(style = "inverted", size = 6),
series = list(
list(
name = "High",
data = c(28, 29, 33, 36, 32, 32, 33)
),
list(
name = "Low",
data = c(12, 11, 14, 18, 17, 13, 13)
)
),
title = list(
text = "Average High & Low Temperature",
align = "left"
),
xaxis = list(
categories = month.abb[1:7]
),
yaxis = list(
title = list(text = "Temperature"),
labels = list(
2020-03-03 17:32:30 +01:00
formatter = htmlwidgets::JS("function(value) {return value + '\u00b0C';}")
2018-07-30 23:04:08 +02:00
)
)
))
```
2020-02-14 18:13:24 +01:00
![](man/figures/raw-api.png)
2018-07-30 23:04:08 +02:00
2021-09-17 11:24:35 +02:00
## Development
This package use [{packer}](https://github.com/JohnCoene/packer) to manage JavaScript assets, see packer's [documentation](https://packer.john-coene.com/#/) for more.
Install nodes modules with:
```r
packer::npm_install()
```
Modify `srcjs/widgets/apexcharter.js`, then run:
```r
packer::bundle()
```
Re-install R package and try `apexcharter()` or `apex()` functions.